QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#592477#7992. 【模板】线段树gogo11WA 2416ms79052kbC++203.4kb2024-09-26 22:51:312024-09-26 22:51:31

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 22:51:31]
  • 评测
  • 测评结果:WA
  • 用时:2416ms
  • 内存:79052kb
  • [2024-09-26 22:51:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int N=200010;
constexpr unsigned int Mod=(1<<20)-1;
unsigned int a[N],C[25][25];
struct segtree
{
    struct Node
    {
        int l,r;
        unsigned int add;
        array<unsigned int,21> p{};
    };
    vector<Node> tr;
    segtree() {}
    segtree(int n) {init(n);}
    void init(int n) {tr.resize(4*n+10);}
    void pushup(Node &u,Node &ls,Node &rs)
    {
        int left=min(20,ls.r-ls.l+1);
        int right=min(20,rs.r-rs.l+1);
        fill(u.p.begin(),u.p.end(),0); 
        for(int i=0;i<=left;i++) {
            for(int j=0;j<=right;j++) {
                if(i+j>20) break;
                u.p[i+j]+=ls.p[i]*rs.p[j];
                u.p[i+j]&=Mod;
            }
        }
    }
    void pushup(int p){pushup(tr[p],tr[p*2],tr[p*2+1]);}
    void pushdown(Node &u,unsigned int x)
    {
        vector<unsigned int> base(21,1);
        for(int i=1;i<=20;i++)
            base[i]=((base[i-1]*x)&Mod);
        int mx=min(20,u.r-u.l+1);
        for(int i=0;i<=mx;i++) {
            for(int j=i+1;j<=mx;j++) {
                u.p[i]+=u.p[j]*C[j][j-i]*base[j-i];
                u.p[i]&=Mod;
            }
        }
        u.add+=x;
        u.add&=Mod;
    }
    void pushdown(Node &u,Node &ls,Node &rs)
    {if(u.add) pushdown(ls,u.add),pushdown(rs,u.add),u.add=0;}
    void pushdown(int p){pushdown(tr[p],tr[p*2],tr[p*2+1]);}
    void build(int p,int l,int r)
    {
        tr[p]={l,r,0,0};
        if(l==r)
        {
            tr[p].p[0]=a[l],tr[p].p[1]=1;
            return;
        }
        int mid=(l+r)>>1;
        build(p*2,l,mid);
        build(p*2+1,mid+1,r);
        pushup(p);
    }
    void update(int p,int x,int y,unsigned int z)
    {
        // cerr<<p<<"  "<<tr[p].l<<"  "<<tr[p].r<<"  "<<x<<"   "<<y<<"  "<<z<<"\n";
        if(x<=tr[p].l && tr[p].r<=y)
        {
            pushdown(tr[p],z);
            return;
        }
        pushdown(p);
        int mid=(tr[p].l+tr[p].r)>>1;
        if(x<=mid)
            update(p*2,x,y,z);
        if(y>mid)
            update(p*2+1,x,y,z);
        pushup(p);
    }
    Node query(int p,int x,int y)
    {
        if(x<=tr[p].l && y>=tr[p].r)
            return tr[p];
        pushdown(p);
        int mid=(tr[p].l+tr[p].r)>>1;
        Node r1,r2,r3;
        if(y<=mid)
            return query(p*2,x,y);
        if(x>mid)
            return query(p*2+1,x,y);
        r1=query(p*2,x,y),r2=query(p*2+1,x,y);
        pushup(r3,r1,r2);
        return r3;
    }
};
void solve()
{
    // for(int i=0;i<=21;i++)
    // {
    //     C[i][0]=1;
    //     for(int j=1;j<=i;j++)
    //         C[i][j]=((C[i-1][j-1]+C[i-1][j])&Mod);
    // }
    for(int i=0;i<=21;i++)
    {
        C[i][0]=C[i][i]=1;
        for(int j=1;j<=i-1;j++)
            C[i][j]=((C[i-1][j-1]+C[i-1][j])&Mod);
    }

    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    segtree tr(n);
    tr.build(1,1,n);
    for(int i=1;i<=q;i++) {
        int o,l,r;
        cin>>o>>l>>r;
        if(o==2) {
            cout<<(tr.query(1,l,r).p[0]&Mod)<<"\n";
            continue;
        }
        int x;
        cin>>x;
        tr.update(1,l,r,x);
    }
}
int main()
{
    ios::sync_with_stdio(false),cin.tie(0);
    int _=1;
    // cin>>_;
    while(_--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

10 10
969575 741825 24903 1047319 450475 256145 1045323 479255 810659 768323
1 5 6 3034
2 1 10
2 1 9
2 1 4
1 3 6 126904
2 5 5
2 9 9
1 7 7 853094
1 4 9 1025178
2 5 8

output:

1045541
1012343
558151
580413
810659
527353

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 2416ms
memory: 79052kb

input:

200000 200000
496015 180543 330721 874799 740427 144379 598057 795949 323465 87657 683935 748203 748665 288301 846003 33033 746029 132621 876629 361899 701297 373189 256151 723161 377571 54947 91151 855991 433965 73347 155081 314317 790527 705555 1035217 298963 604641 203865 230029 802437 720769 843...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 1st lines differ - expected: '746709', found: '0'