Codeforces Round #141 (Div. 2), problem: (D) Zigzag 線段樹 整形變數注意溢出控制

來源:互聯網
上載者:User

做法:一開始沒有注意整形資料進行LL 的處理啊..

#include<cstdio>#include<cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1typedef 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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.