QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#782785 | #9438. Two Box | strlen_s_ | WA | 31ms | 100028kb | C++17 | 4.4kb | 2024-11-25 21:27:01 | 2024-11-25 21:27:03 |
Judging History
answer
#include<bits/stdc++.h>
#define ls (k<<1)
#define rs (k<<1|1)
#define mid (l+r>>1)
#define ll long long
using namespace std;
const int M=3e4+10,N=16,mod=998244353,inv2=499122177,B=15;
ll C[N][N],ivC[N][N];
ll xs[N][N][N];
int n,m,q;
ll pw[N];
ll dp[M][N][N];
int a[M];
struct node{
ll c[N];
void init(int len){
memset(c,0,sizeof(c));
for(int i=0;i<=len;i++)c[i]=1;
}
};
node merge(node a,node b,int len){
for(int i=0;i<=len;i++)a.c[i]=a.c[i]*b.c[i]%mod;
return a;
}
struct segtree{
node v[M<<2];
int cnt[M<<2],sm[M<<2];
int ik;
void pushup(int k){v[k]=merge(v[ls],v[rs],ik),cnt[k]=cnt[ls]+cnt[rs],sm[k]=sm[ls]+sm[rs];}
void build(int k,int l,int r){
cnt[k]=r-l+1;v[k].init(ik);
if(l==r)return;
build(ls,l,mid),build(rs,mid+1,r);
}
void upd(int k,int l,int r,int x,node z,int z2,int z3){
if(x>n)return;
if(l==r){v[k]=z,cnt[k]+=z2,sm[k]=z3;return;}
if(mid>=x)upd(ls,l,mid,x,z,z2,z3);
else upd(rs,mid+1,r,x,z,z2,z3);
pushup(k);
}
void qry(int k,int l,int r,int x,int y,node &ans,int &sum){
if(x<=l&&r<=y){
ans=merge(ans,v[k],ik);
sum+=sm[k];
return;
}
if(mid>=x)qry(ls,l,mid,x,y,ans,sum);
if(y>mid)qry(rs,mid+1,r,x,y,ans,sum);
}
int findl(int k,int l,int r,int x){
if(x<1)return 0;
if(!cnt[k])return 0;
if(l==r)return l+1;
if(mid>=x)return findl(ls,l,mid,x);
int p=findl(rs,mid+1,r,x);
if(p)return p;
return findl(ls,l,mid,x);
}
int findr(int k,int l,int r,int x){
if(x>n)return n+1;
if(!cnt[k])return n+1;
if(l==r)return r;
if(mid>=x){
int p=findr(ls,l,mid,x);
if(p!=n+1)return p;
return findr(rs,mid+1,r,x);
}
return findr(rs,mid+1,r,x);
}
}T[N];
ll ksm(ll a,int b){
ll res=1;
while(b){
if(b&1)res=res*a%mod;
a=a*a%mod,b>>=1;
}
return res;
}
void init(){
C[0][0]=1;
for(int i=1;i<=B;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<=B;i++)
for(int j=0;j<=i;j++)
ivC[i][j]=ksm(C[i][j],mod-2);
for(int i=0;i<=B;i++)dp[0][i][0]=1;
for(int i=1;i<=3e4;i++)
for(int j=0;j<=B;j++)
for(int k=0;k<=j;k++)
dp[i][j][k]=((k+1<=j?dp[i-1][j][k+1]*(k+1):0)+(k?dp[i-1][j][k-1]*(j-k+1):0))%mod;
for(int i=0;i<=3e4;i++)
for(int j=0;j<=B;j++)
for(int k=0;k<=j;k++)
dp[i][j][k]=dp[i][j][k]*ivC[j][k]%mod;
for(int l=0;l<=B;l++)
for(int i=0;i<=l;i++)
for(int j=0;j<=l;j++)
for(int k=0;k<=min(i,j);k++)
xs[l][i][j]=(xs[l][i][j]+((k&1)?mod-1:1)*C[i][k]%mod*C[l-i][j-k])%mod;
pw[0]=1;
for(int i=1;i<=B;i++)pw[i]=pw[i-1]*inv2%mod;
}
void FWT(ll *c,int len,ll z){
ll rec[N]={0};
for(int i=0;i<=len;i++)
for(int j=0;j<=len;j++)
rec[i]=(rec[i]+c[j]*xs[len][i][j]%mod*z)%mod;
for(int i=0;i<=len;i++)c[i]=rec[i];
}
void mdf(int k,int p){
if(p<1||p>n)return;
int l=max(T[k].findl(1,1,n,p),1),tr=T[k].findr(1,1,n,p),r=min(tr,n),len=r-l+1;
if(l>r)return;
node z;z.init(k);
T[k].upd(1,1,n,p+1,z,0,0);
if(k==m){
for(int i=0;i<=k;i++)z.c[i]=dp[len][k][i];
if(tr==n+1)for(int i=0;i<k;i++)z.c[i]=(z.c[i]+z.c[i+1])%mod;
z.c[k]=0;
FWT(z.c,k-1,1);
T[k].upd(1,1,n,l,z,0,r-l+1);
return;
}
node ans;ans.init(k);int sum=0;
T[k+1].qry(1,1,n,l,r,ans,sum);
len-=sum;
for(int i=0;i<=k;i++)z.c[i]=dp[len][k][i];
FWT(z.c,k,1);
for(int i=0;i<=k;i++)z.c[i]=z.c[i]*ans.c[i]%mod;
FWT(z.c,k,pw[k]);
if(tr==n+1)for(int i=0;i<k;i++)z.c[i]=(z.c[i]+z.c[i+1])%mod;
z.c[k]=0;
FWT(z.c,k-1,1);
T[k].upd(1,1,n,l,z,0,r-l+1);
}
void upd(int p,int z){
if(a[p]==z)return;
node c;
if(a[p]<z){
for(int i=z;i>a[p];i--){
c.init(i-1);
T[i].upd(1,1,n,p,c,-1,0);
mdf(i,p);
}
}
else{
for(int i=a[p];i>z;i--){
c.init(i-1);
T[i].upd(1,1,n,p,c,1,0);
mdf(i,p-1),mdf(i,p+1);
}
}
for(int i=min(a[p],z);i>=2;i--)mdf(i,p);
a[p]=z;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
init();
cin>>n>>m>>q;
for(int i=2;i<=m;i++)T[i].ik=i-1,T[i].build(1,1,n);
for(int i=1;i<=n;i++)a[i]=1;
for(int i=1,x;i<=n;i++){
cin>>x;
upd(i,x);
}
while(q--){
int p,x;
cin>>p>>x;
upd(p,x);
cout<<T[2].v[1].c[0]<<'\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 13ms
memory: 73468kb
input:
3 3 2 1 3 1 3 2 1 3
output:
5 14
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 16ms
memory: 86316kb
input:
6 8 1 3 8 7 7 1 6 1 4
output:
2100
result:
ok "2100"
Test #3:
score: 0
Accepted
time: 20ms
memory: 95844kb
input:
12 10 8 1 3 2 6 3 6 7 7 5 5 4 7 12 4 7 10 4 2 9 8 9 9 8 3 4 9 10 2
output:
2741280 3007680 1503840 1916160 1972800 728640 1821600 621440
result:
ok 8 tokens
Test #4:
score: 0
Accepted
time: 17ms
memory: 80280kb
input:
1939 5 1 5 1 1 2 1 5 4 5 3 1 2 1 3 3 1 2 3 5 5 3 2 2 1 3 1 5 1 4 2 5 4 1 5 4 3 4 5 3 3 3 3 2 1 2 3 5 1 4 2 1 4 1 3 5 2 2 1 4 4 5 3 2 3 2 1 1 5 5 5 5 3 4 3 1 3 1 1 1 3 5 3 5 1 5 4 3 2 1 2 2 2 3 5 2 4 2 3 1 2 5 5 1 2 5 2 5 3 3 3 4 5 1 5 4 5 3 3 5 4 5 3 5 3 2 2 5 3 2 4 3 3 4 2 2 1 3 1 3 5 2 3 4 2 3 2 4...
output:
894246250
result:
ok "894246250"
Test #5:
score: 0
Accepted
time: 7ms
memory: 89144kb
input:
245 9 1 2 2 3 6 7 5 7 4 7 9 7 6 3 1 6 8 2 1 1 5 3 1 1 3 1 6 8 4 8 4 8 1 8 6 6 9 3 4 7 1 5 2 3 9 5 7 5 7 7 5 5 5 5 1 5 4 7 1 2 6 8 9 5 4 1 8 6 3 9 9 1 3 6 5 5 5 1 6 5 1 2 5 5 4 1 1 8 3 8 2 9 7 9 5 7 8 8 5 9 1 1 4 4 9 9 6 3 9 8 9 2 1 2 6 9 2 1 3 7 3 2 5 9 3 7 2 2 3 4 7 5 1 8 5 8 6 7 9 7 4 8 7 2 2 7 5 ...
output:
99945033
result:
ok "99945033"
Test #6:
score: 0
Accepted
time: 19ms
memory: 96472kb
input:
1919 9 1 7 1 7 6 6 9 8 5 1 8 9 9 7 3 4 2 8 9 4 8 7 4 8 8 8 4 2 9 5 9 3 7 2 3 2 8 7 9 1 1 3 7 7 2 5 9 2 1 3 6 7 6 4 4 1 9 3 7 3 2 5 5 1 4 7 8 6 2 1 4 7 1 4 7 4 7 6 3 8 4 3 7 3 1 7 5 2 2 2 4 9 1 5 5 7 7 3 1 5 4 7 2 9 5 4 9 3 2 6 8 2 3 8 3 6 5 5 5 9 7 2 8 2 9 5 1 8 6 3 1 2 9 1 9 1 3 9 6 7 2 3 2 2 7 9 7...
output:
292474819
result:
ok "292474819"
Test #7:
score: 0
Accepted
time: 15ms
memory: 81008kb
input:
1985 5 1 1 5 5 1 4 4 3 2 1 4 4 1 1 2 5 5 5 3 3 1 2 4 3 3 5 5 2 4 1 1 5 4 3 1 2 5 5 4 1 5 2 5 2 4 1 4 5 1 3 4 4 2 2 4 5 2 1 5 5 3 2 5 5 2 4 4 5 2 5 1 1 5 5 1 1 3 4 2 4 5 2 1 2 1 1 2 3 5 1 5 2 4 1 5 3 2 2 3 1 3 4 5 1 4 4 2 4 3 5 5 1 4 3 4 5 5 2 5 2 2 2 2 2 3 5 1 4 4 3 3 4 5 5 4 3 5 1 4 5 5 2 3 2 2 3 3...
output:
810807913
result:
ok "810807913"
Test #8:
score: 0
Accepted
time: 13ms
memory: 78564kb
input:
357 5 1 1 3 2 5 4 4 3 4 3 1 1 1 4 5 5 2 1 3 4 1 3 1 2 3 4 1 5 3 1 3 5 1 4 4 2 4 5 1 3 4 2 5 2 3 2 5 3 2 2 1 4 3 1 1 2 3 2 3 2 1 4 4 5 5 1 4 2 1 2 2 2 4 1 3 5 1 1 2 4 4 5 4 1 2 4 1 2 3 2 4 3 4 3 4 1 4 1 1 4 5 4 4 4 3 2 5 4 5 4 2 4 1 2 5 5 3 5 5 2 4 2 1 2 1 4 1 2 1 3 1 5 2 2 1 5 2 2 4 5 1 3 4 5 3 3 3 ...
output:
836628563
result:
ok "836628563"
Test #9:
score: 0
Accepted
time: 11ms
memory: 96064kb
input:
858 10 1 1 9 2 9 6 9 6 10 9 4 1 9 7 7 9 2 5 6 9 3 4 7 4 2 5 10 8 10 4 8 8 1 2 9 10 9 5 9 1 2 1 8 10 2 8 1 10 6 9 5 2 4 9 4 1 5 6 10 7 5 1 7 6 7 9 8 4 4 1 8 1 4 4 10 8 10 1 1 1 2 6 3 6 9 8 10 4 5 8 3 6 7 2 9 9 7 9 10 5 7 4 9 4 7 3 1 10 2 6 4 1 5 8 7 1 6 1 2 8 8 1 3 6 8 5 3 10 9 8 4 8 5 2 2 2 10 8 1 8...
output:
699591879
result:
ok "699591879"
Test #10:
score: 0
Accepted
time: 19ms
memory: 87644kb
input:
884 7 1 7 2 6 7 1 7 2 5 5 1 7 5 4 5 2 5 4 2 2 4 3 2 7 1 6 3 3 2 1 1 2 1 7 7 4 3 5 1 1 6 6 7 5 1 6 6 4 3 5 2 3 1 6 3 7 2 7 4 6 6 6 3 7 6 1 3 2 1 1 5 4 3 1 4 4 4 7 2 5 7 5 7 5 3 6 5 5 1 4 5 6 6 6 3 6 7 3 2 3 1 5 5 6 7 6 5 3 2 7 3 1 2 5 5 1 2 7 5 3 1 3 6 4 7 2 4 4 5 6 7 4 7 4 2 4 1 2 1 2 6 7 1 7 4 1 1 ...
output:
298342150
result:
ok "298342150"
Test #11:
score: 0
Accepted
time: 19ms
memory: 96992kb
input:
2000 10 1 7 2 5 8 9 1 9 9 5 4 3 3 9 7 3 2 1 9 9 6 4 9 10 10 1 1 2 4 6 7 9 9 5 5 8 1 3 9 5 2 5 7 10 8 5 10 1 9 8 10 2 1 9 4 1 10 8 3 10 4 4 7 5 6 6 1 4 4 4 6 5 10 5 7 7 9 2 3 9 4 8 8 9 9 4 6 5 9 5 4 3 10 3 5 7 5 9 8 1 9 2 9 4 3 3 4 6 3 1 5 2 10 2 2 3 4 5 2 4 6 2 9 5 10 5 2 9 4 9 8 8 7 5 7 3 10 2 6 6 ...
output:
593281642
result:
ok "593281642"
Test #12:
score: 0
Accepted
time: 27ms
memory: 97236kb
input:
2000 10 1 4 3 9 2 9 3 9 2 7 1 4 10 1 10 8 10 1 6 9 5 7 5 10 10 1 10 5 7 1 5 5 8 10 10 4 10 6 6 1 9 8 5 2 3 5 3 1 1 3 3 6 2 6 9 8 4 10 8 7 8 9 10 5 3 6 3 2 4 10 1 10 8 7 10 7 1 4 3 2 8 8 7 7 9 1 7 5 3 5 7 6 6 9 8 8 8 9 7 10 8 3 5 5 1 3 10 9 1 9 2 10 9 3 1 6 1 7 10 9 9 9 3 6 9 2 10 6 1 5 2 2 5 6 6 9 1...
output:
635535966
result:
ok "635535966"
Test #13:
score: 0
Accepted
time: 16ms
memory: 99892kb
input:
2000 10 1 7 6 2 4 9 3 2 10 6 2 3 2 8 7 4 1 6 7 1 10 4 9 7 2 5 2 5 10 6 6 5 3 7 4 10 6 4 8 7 9 6 10 10 3 10 4 3 6 6 6 8 5 6 4 3 9 2 9 8 5 6 5 5 4 9 7 6 1 7 1 8 10 3 1 10 3 4 4 9 10 10 7 8 4 4 6 9 3 6 3 4 4 3 4 7 1 6 2 6 4 9 10 4 2 7 7 10 4 4 1 10 2 8 6 8 2 8 1 4 10 3 6 1 1 7 9 3 9 6 2 3 9 8 3 7 9 3 8...
output:
336713065
result:
ok "336713065"
Test #14:
score: 0
Accepted
time: 24ms
memory: 97652kb
input:
2000 10 1 10 10 2 4 8 7 8 9 8 7 5 10 8 2 5 5 1 3 10 5 4 3 6 3 9 9 10 9 9 9 6 10 6 2 9 3 7 4 7 10 2 4 7 3 9 3 7 10 5 9 10 7 8 1 7 7 9 10 6 4 10 4 3 6 10 5 4 7 5 6 8 8 1 6 5 7 7 5 4 2 5 8 5 9 9 9 7 10 2 9 7 6 1 8 9 2 4 1 9 8 7 9 4 2 3 2 3 2 7 5 4 8 8 2 4 8 6 4 1 3 3 9 7 10 7 7 3 8 1 1 4 2 3 4 10 8 8 8...
output:
85227947
result:
ok "85227947"
Test #15:
score: 0
Accepted
time: 27ms
memory: 100028kb
input:
2000 10 1 1 7 2 8 1 9 7 7 6 2 4 2 1 5 2 6 1 10 2 8 5 1 6 8 5 9 10 5 8 2 1 2 8 6 2 3 7 9 10 10 10 9 9 3 6 1 7 8 4 8 9 7 9 5 1 3 8 1 3 4 1 6 6 5 9 6 7 8 10 10 4 9 5 6 10 7 2 3 4 7 3 8 6 3 5 2 2 9 9 5 8 3 6 8 2 1 4 3 4 2 3 9 6 4 5 6 8 1 2 1 3 10 4 5 7 2 9 4 10 6 1 6 1 2 10 2 3 9 5 9 1 6 10 2 8 6 10 6 1...
output:
913697441
result:
ok "913697441"
Test #16:
score: 0
Accepted
time: 19ms
memory: 97708kb
input:
2000 10 1 7 9 2 6 9 1 10 1 8 3 4 5 1 10 6 10 4 10 3 1 10 2 10 8 3 5 2 2 4 9 5 7 2 4 8 5 7 5 1 10 8 10 5 8 10 4 2 9 8 9 6 3 7 10 1 7 6 9 4 10 8 5 1 3 5 7 3 6 3 2 8 5 6 2 8 2 7 6 1 6 7 4 3 5 8 3 8 9 5 6 2 8 2 4 5 2 4 1 3 9 7 1 5 9 9 2 3 2 1 8 6 1 3 6 7 3 5 5 8 3 9 5 9 1 7 2 3 5 1 7 8 10 3 4 10 8 3 6 8...
output:
298067446
result:
ok "298067446"
Test #17:
score: 0
Accepted
time: 31ms
memory: 97256kb
input:
2000 10 1 3 6 1 8 2 3 8 7 9 8 8 5 3 4 4 2 9 1 2 4 7 3 3 3 2 3 9 9 4 4 1 1 1 2 2 4 3 7 8 2 2 1 9 2 7 10 9 5 10 8 1 8 6 2 4 9 2 7 8 2 2 1 1 8 10 8 7 7 1 5 2 4 9 3 2 1 7 1 1 6 1 7 1 7 6 9 6 1 2 3 6 10 3 10 3 2 6 7 10 6 2 6 2 6 7 2 2 7 2 1 6 5 10 5 2 2 10 4 1 9 8 8 7 6 1 9 2 4 1 4 5 7 5 3 10 4 9 5 2 8 8...
output:
307824286
result:
ok "307824286"
Test #18:
score: -100
Wrong Answer
time: 16ms
memory: 64716kb
input:
2000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
0
result:
wrong answer 1st words differ - expected: '1', found: '0'