做法:一开始没有注意整形数据进行LL 的处理啊..
#include<cstdio> #include<cstring> #define left l,m,x<<1 #define right m+1,r,x<<1|1 typedef long long LL; const int LMT=100003; //编程习惯不好啊》。。 LL sum[5][12][LMT<<2]; int Z; LL query(int L,int R,int l,int r,int x) { if(L<=l&&r<=R) return sum[Z-2][(l -L +1)%((Z<<1)-2)][x]; int m=(l+r)>>1; LL res=0; if(L<=m)res+=query(L,R,left); if(R>m)res+=query(L,R,right); return res; } void update(int op,int pos,int l,int r,int x) { if(l==r) { int i,j; for(i=2;i<=6;++i) for(j=0;j<(i<<1)-2;++j) if(j>i)sum[i - 2][j][x]=op*((LL(i)<<1)-j);//这里啊 else if(j>0&&j<=i)sum[i - 2][j][x]=LL(1)*op*j; else sum[i - 2][j][x]=LL(op)<<1; return; } int m=(l+r)>>1,i,j,le=m-l+1; if(pos<=m)update(op,pos,left); else update(op,pos,right); for(i=2;i<=6;++i) for(j=0;j<(i<<1)-2;++j) sum[i - 2][j][x]=sum[i - 2][j][x<<1]+sum[i - 2][(j+le)%((i<<1)-2)][x<<1|1]; } int main(void) { //一开始写了两个%d。。。 int l,r,i,n,t,v, x; scanf("%d",&n); for(i=1;i<=n;++i) { scanf("%d",&x); update(x,i,1,n,1); } scanf("%d",&t); while(t--) { scanf("%d",&x); if(1==x) { scanf("%d%d",&l,&v); update(v,l,1,n,1); } else { scanf("%d%d%d",&l,&r,&Z); printf("%I64d\n",query(l,r,1,n,1)); } } return 0; }