QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#205501 | #7561. Digit DP | ucup-team1004# | TL | 1ms | 7984kb | C++14 | 3.1kb | 2023-10-07 16:18:56 | 2023-10-07 16:18:56 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=5e4+5,M=5e4+5,K=2e7+5,mod=998244353,Mod=mod-1;const db eps=1e-6;const ll INF=1e18+7;mt19937 rnd(263082);
int n,q,Rt,k,A[N],op[N],Z[N];LL X[N],Y[N];
void read(LL &x){x=0;char c=Gc();while(c<'0'||c>'9') c=Gc();while(c>='0'&&c<='9') x=x*2+c-48,c=Gc();}
ll ans[3];
int __lg(LL x){int cnt=0;while(x) cnt++,x>>=1;return cnt;}
const int inv2=(mod+1)/2,inv6=(mod+1)/6;
namespace Tree{
int L[K],R[K],Ct;ll f[K][3];
void Up(int v){for(int i=0;i<3;i++) f[v][i]=(f[L[v]][i]+f[R[v]][i])%mod;}
void Add(int x,int y,int &v,LL l=0,LL r=k){
if(!v) v=++Ct;if(y<l||x>r) return;if(x<=l&&r<=y) return;
LL m=l+r>>1;Add(x,y,L[v],l,m);Add(x,y,R[v],m+1,r);
}
void BD(int v,LL l=0,LL r=k){
if(!L[v]&&!R[v]) {
int d=__lg(l^r),Le=(r-l+1)%mod;
ll g[4],s[4];Me(g,0);Me(s,0);g[0]=1;
for(int i=0;i<n;i++)if(r>>i&1){
Mc(s,g);
g[1]+=s[0]*A[i]%mod*(i<d?inv2:1)%mod;g[2]+=s[1]*A[i]%mod*(i<d?inv2:1)%mod;g[3]+=s[2]*A[i]%mod*(i<d?inv2:1)%mod;
g[2]+=s[0]*A[i]%mod*A[i]%mod*(i<d?inv2:1)%mod*inv2%mod;g[3]+=s[1]*A[i]%mod*A[i]%mod*(i<d?inv2:1)%mod*inv2%mod;
g[3]+=s[0]*A[i]%mod*A[i]%mod*A[i]%mod*(i<d?inv2:1)%mod*inv6%mod;
}
f[v][0]=g[1]*Le%mod;f[v][1]=g[2]*2%mod*Le%mod;f[v][2]=g[3]*6%mod*Le%mod;
// cerr<<(ll)l<<' '<<(ll)r<<' '<<f[v][0]<<' '<<f[v][1]<<' '<<f[v][2]<<'\n';
return;
}
LL m=l+r>>1;BD(L[v],l,m);BD(R[v],m+1,r);Up(v);
}
ll g[K];
void PF(int v,ll w,LL Le){
g[v]=(g[v]+w)%mod;Le%=mod;
f[v][2]=(f[v][2]+3*f[v][1]*w%mod+3*f[v][0]*w%mod*w%mod+Le*w*w%mod*w)%mod;
f[v][1]=(f[v][1]+2*f[v][0]*w%mod+Le*w%mod*w%mod);
f[v][0]=(f[v][0]+Le*w)%mod;
}
void P(int v,LL Le){g[v]&&(PF(L[v],g[v],Le>>1),PF(R[v],g[v],Le>>1),g[v]=0);}
void Ins(LL x,LL y,int z,int v,LL l=0,LL r=k){
if(x<=l&&r<=y) return PF(v,z,r-l+1);LL m=l+r>>1;P(v,r-l+1);
x<=m&&(Ins(x,y,z,L[v],l,m),0);y>m&&(Ins(x,y,z,R[v],m+1,r),0);Up(v);
}
void qry(LL x,LL y,int v,int l=0,int r=k){
if(x<=l&&r<=y) {for(int i=0;i<3;i++) ans[i]+=f[v][i];return;}LL m=l+r>>1;P(v,r-l+1);
x<=m&&(qry(x,y,L[v],l,m),0);y>m&&(qry(x,y,R[v],m+1,r),0);
}
}
void Solve(){
int i,j;scanf("%d%d",&n,&q);k=((LL)1<<n)-1;
for(i=0;i<n;i++) scanf("%d",&A[i]);
for(i=1;i<=q;i++){
scanf("%d",&op[i]);read(X[i]);read(Y[i]);
if(op[i]==1) scanf("%d",&Z[i]);
Tree::Add(X[i],Y[i],Rt);
}
Tree::BD(Rt);
for(i=1;i<=q;i++){
if(op[i]==1) Tree::Ins(X[i],Y[i],Z[i],Rt);
else {
Me(ans,0);Tree::qry(X[i],Y[i],Rt);
for(j=0;j<3;j++) ans[j]%=mod;
printf("%lld\n",(ans[0]*ans[0]%mod*ans[0]+3*(mod-ans[1])*ans[0]+2*ans[2])%mod*(mod+1)/6%mod);
}
}
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7920kb
input:
3 3 1 2 4 2 000 111 1 010 101 1 2 000 111
output:
1960 3040
result:
ok 2 number(s): "1960 3040"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7984kb
input:
2 2 1 1 2 00 10 2 00 11
output:
0 2
result:
ok 2 number(s): "0 2"
Test #3:
score: -100
Time Limit Exceeded
input:
99 49952 470888 74578 802746 396295 386884 721198 628655 722503 207868 647942 87506 792718 761498 917727 843338 908043 952768 268783 375312 414369 319712 96230 277106 168102 263554 936674 246545 667941 198849 268921 191459 436316 134606 802932 515506 837311 465964 394766 17626 650419 984050 790137 4...