QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#294297#7992. 【模板】线段树daduoli#TL 2ms9968kbC++142.2kb2023-12-30 11:26:032023-12-30 11:26:03

Judging History

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

  • [2023-12-30 11:26:03]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:9968kb
  • [2023-12-30 11:26:03]
  • 提交

answer

#include<bits/stdc++.h>
#define lc(p) p<<1
#define rc(p) p<<1|1
using namespace std;
typedef long long LL;
inline int read(){
    char ch=getchar();
    while(!isdigit(ch) && ch!='-') ch=getchar();
    int x=0,ff=1; if(ch=='-') ff=-1,ch=getchar();
    while(isdigit(ch)) x=(x<<3) + (x<<1) + (ch^48),ch=getchar();
    return x*ff;
}
const int N=2e5+5,P=1<<20;
int n,Q,a[N];
struct node{
    int mx[20];
    node operator + (node A) const {
        node B; for(int i=0;i<20;i++) B.mx[i]=0;
        for(int i=0;i<20;i++)
            for(int j=0;j<20-i;j++) (B.mx[i+j]+=1ll*mx[i]*A.mx[j]%P)%=P;
        return B;
    }
} tr[N<<2]; int tg[N<<2],bfw[20],lm[N<<2],C[N][20];
void addt(int p,int w){
    (tg[p]+=w)%=P; bfw[0]=1;
    for(int i=1;i<20;i++) bfw[i]=1ll*bfw[i-1]*w%P;
    for(int i=19;i>=0;i--)
        for(int j=0;j<i;j++) (tr[p].mx[i]+=1ll*tr[p].mx[j]*bfw[i-j]%P*C[lm[p]-j][i-j])%=P;
}
void pushup(int p){ tr[p]=tr[lc(p)]+tr[rc(p)]; }
void pushdn(int p){
    if(tg[p]) addt(lc(p),tg[p]),addt(rc(p),tg[p]),tg[p]=0;
}
void build(int p,int L,int R){
    lm[p]=R-L+1; if(L==R) { tr[p].mx[0]=1; tr[p].mx[1]=a[L]; return ;}
    int mid=(L+R)/2; build(lc(p),L,mid); build(rc(p),mid+1,R); pushup(p);
}
void Mdf(int p,int L,int R,int lt,int rt,int w){
    if(L>rt || R<lt) return ;
    if(L>=lt && R<=rt) {addt(p,w); return ;} 
    int mid=(L+R)/2; pushdn(p);
    Mdf(lc(p),L,mid,lt,rt,w); Mdf(rc(p),mid+1,R,lt,rt,w); pushup(p);
}
node Qry(int p,int L,int R,int lt,int rt){
    if(L>=lt && R<=rt) return tr[p];
    int mid=(L+R)/2; pushdn(p);
    if(rt<=mid) return Qry(lc(p),L,mid,lt,rt);
    else if(lt>mid) return Qry(rc(p),mid+1,R,lt,rt);
    else return Qry(lc(p),L,mid,lt,rt)+Qry(rc(p),mid+1,R,lt,rt);
}
int main(){
    n=read(); Q=read();
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<20;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%P;
    }
    for(int i=1;i<=n;i++) a[i]=read()-1;
    build(1,1,n);
    while(Q--){
        int o=read(),l=read(),r=read(),w;
        if(o==1) w=read(),Mdf(1,1,n,l,r,w);
        else {
            node bf=Qry(1,1,n,l,r);
            int ans=0; for(int i=0;i<20;i++) (ans+=bf.mx[i])%=P;
            printf("%d\n",ans);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9968kb

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
Time Limit Exceeded

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:

746709
564663
426791
840425
-286375
413693
-167433
-514189
189149
257625
60619
958793
250635
-179497
383765
151047
272239
146175
46215
-134317
-431065
698623
381177
-115797
-255871
785375
1044293
202971
508317
237901
-413657
646839
38501
304017
889609
214899
617927
720071
628729
202369
420511
528565...

result: