设为首页 加入收藏

TOP

CF 228D Zigzag(线段树) (二)
2015-11-21 01:15:52 来源: 作者: 【 】 浏览:5
Tags:228D Zigzag 线段
,int r,int z,int x){
? ? if(L[step].left==l&&L[step].right==r){
? ? ? ? // mod z == x
? ? ? ? return L[step].sum[z][x];
? ? }
? ? int m=(L[step].left+L[step].right)>>1;
? ? if(r<=m) return query(lson,l,r,z,x);
? ? else if(l>m) return query(rson,l,r,z,x);
? ? else return query(lson,l,m,z,x)+query(rson,m+1,r,z,(x+(m-l+1))%(2*(z-1)));
}
void update(int step,int pos,int val){
? ? if(L[step].left==pos&&L[step].right==pos){
? ? ? ? // mod (2*(i-1)) == j
? ? ? ? for(int i=2;i<=6;i++)
? ? ? ? ? ? for(int j=0;j<2*(i-1);j++)
? ? ? ? ? ? ? ? L[step].sum[i][j]=(LL)val*s[i][j];
? ? ? ? return ;
? ? }
? ? int m=(L[step].left+L[step].right)>>1;
? ? if(pos<=m) update(lson,pos,val);
? ? else update(rson,pos,val);
? ? push_up(step);
}
int main(){
? ? Init();
? ? scanf("%d",&n);
? ? for(int i=1;i<=n;i++)
? ? ? ? scanf("%d",&a[i]);
? ? bulid(1,1,n);
? ? scanf("%d",&m);
? ? while(m--){
? ? ? ? int k,l,r,z;
? ? ? ? scanf("%d",&k);
? ? ? ? if(k==1){
? ? ? ? ? ? scanf("%d%d",&l,&z);
? ? ? ? ? ? update(1,l,z);
? ? ? ? }
? ? ? ? else{
? ? ? ? ? ? scanf("%d%d%d",&l,&r,&z);
? ? ? ? ? ? printf("%I64d\n",query(1,l,r,z,1));
? ? ? ? }
? ? }
? ? return 0;
}
?
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇CF 23E(Tree-树-背包合并) 下一篇POJ3006:Dirichlet's Theorem..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: