QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#747966 | #1831. Bruteforce | ocharin | WA | 2ms | 4156kb | C++20 | 3.5kb | 2024-11-14 18:53:13 | 2024-11-14 18:53:14 |
Judging History
answer
/*
_/ _/
_/_/ _/_/_/ _/_/_/ _/_/_/ _/ _/_/ _/_/_/
_/ _/ _/ _/ _/ _/ _/ _/_/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
_/_/ _/_/_/ _/ _/ _/_/_/ _/ _/ _/ _/
*/
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
int c[8][8];
int n,k,w;
struct SegmentTree{
struct tree{
array<int,6>s1,s2;
int sz;
tree():s1({0,0,0,0,0,0}),s2({0,0,0,0,0,0}),sz(0){}
void set(int x){
sz=(x?1:0);
s1.fill(x);
for(int i=0;i<w;++i){
s2[i]=x%w;
for(int j=0;j<k;++j){
s2[i]=s2[i]*i%w;
}
}
}
friend tree operator+(const tree&x,const tree&y){
tree z=x;
z.sz+=y.sz;
vector<int>pw(k+1);
pw[0]=1;
for(int i=1;i<=k;++i) pw[i]=pw[i-1]*x.sz%mod;
for(int i=0;i<=k;++i){
for(int j=0;j<=i;++j){
z.s1[i]+=c[i][j]*pw[i-j]%mod*y.s1[j]%mod;
if(z.s1[i]>=mod) z.s1[i]-=mod;
}
}
for(int i=0;i<w;++i){
z.s2[i]+=y.s2[(i+x.sz)%w];
if(z.s2[i]>=mod) z.s2[i]-=mod;
}
return z;
}
};
vector<tree>s;
SegmentTree(int n=0){
s.assign(n+1<<2,{});
}
void modify(int u,int cl,int cr,int k,int x){
if(cl==cr){
s[u].set(x);
return;
}
int mid=cl+cr>>1;
if(k<=mid) modify(u<<1,cl,mid,k,x);
else modify(u<<1|1,mid+1,cr,k,x);
s[u]=s[u<<1]+s[u<<1|1];
}
void dfs(int u,int cl,int cr){
cerr<<cl<<" "<<cr<<" : "<<s[u].sz<<" ; ";
for(int i=0;i<w;++i) cerr<<s[u].s2[i]<<",";
cerr<<endl;
if(cl==cr) return;
int mid=cl+cr>>1;
dfs(u<<1,cl,mid);
dfs(u<<1|1,mid+1,cr);
}
};
int qpow(int a,int b){
int ans=1;
for(;b;b>>=1){
if(b&1) ans=ans*a%mod;
a=a*a%mod;
}
return ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
c[0][0]=1;
for(int i=1;i<8;++i){
c[i][0]=1;
for(int j=1;j<=i;++j){
c[i][j]=c[i-1][j]+c[i-1][j-1];
}
}
cin>>n>>k>>w;
vector<int>a(n+1);
vector<int>have={0};
for(int i=1;i<=n;++i){
cin>>a[i];
have.push_back(a[i]);
}
int q;
cin>>q;
vector<int>p(q),x(q);
for(int i=0;i<q;++i){
cin>>p[i]>>x[i];
have.push_back(x[i]);
}
sort(have.begin(),have.end());
int sz=have.size()-1;
// for(int i=1;i<=sz;++i) cout<<have[i]<<" \n"[i==sz];
vector<int>cnt(sz+2,0ll);
auto get=[&](int x)->int{
int y=lower_bound(have.begin(),have.end(),x)-have.begin();
int ans=y+cnt[y];
cnt[y]++;
return ans;
};
SegmentTree seg(sz);
int inv=qpow(w,mod-2);
vector<int>d(n+1);
for(int i=1;i<=n;++i) seg.modify(1,1,sz,d[i]=get(a[i]),a[i]);
for(int i=0;i<q;++i){
seg.modify(1,1,sz,d[p[i]],0);
seg.modify(1,1,sz,d[p[i]]=get(x[i]),x[i]);
cout<<inv*(seg.s[1].s1[k]+mod-seg.s[1].s2[1])%mod<<"\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
3 1 1 2 2 8 2 2 5 3 6
output:
36 30
result:
ok 2 number(s): "36 30"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
4 2 2 1 3 3 7 4 1 1 2 4 3 8 4 8
output:
75 80 103 108
result:
ok 4 number(s): "75 80 103 108"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
10 1 1 16251 28898 58179 69362 48663 81443 34949 87167 16552 58931 10 6 89124 8 27159 4 7332 1 15852 9 67405 7 19413 10 97472 7 31114 6 31847 5 43794
output:
3511390 3107346 2780002 2779204 3079414 3018965 3365708 3406982 2970195 2936112
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
100 2 2 44625 87890 57662 73552 89172 64466 22834 24089 60132 5187 88984 19022 67559 53954 42114 19018 80035 3367 50518 15479 72359 15452 38886 5945 34974 86214 16805 71388 48981 45377 34170 61384 88881 29453 94738 94669 56746 80508 79155 94505 82745 38134 41769 2032 23186 5636 39727 54400 86133 497...
output:
81216962 152846115 156547587 163221145 293598979 178882623 92185541 202208317 181562234 200670345 213033267 262881364 247600647 301317991 271334928 261885869 261690216 247578015 236998290 291971331 293746018 424418987 402413699 300515771 300819876 344295103 391424353 392633865 361623113 355154190 47...
result:
ok 100 numbers
Test #5:
score: 0
Accepted
time: 2ms
memory: 4096kb
input:
1000 5 5 67444 21858 17070 50937 22108 62205 2999 96284 84111 16255 69173 11611 84406 28349 95817 86160 87289 19642 22706 44359 31899 36187 15946 86429 23120 65928 81187 32204 37790 18497 52182 23455 59579 78480 45277 57706 60123 99315 19014 72404 35420 14632 12210 38628 1729 18606 23941 96652 80784...
output:
448982964 318631979 90368327 811603500 536477662 692557229 62990700 201293231 656272078 39300199 904902483 682330227 415437174 172036954 307435785 263728224 240392540 817310695 279181829 609019128 744046644 313110033 146349180 684606480 105663106 927540631 395442598 940076193 928045549 210861570 871...
result:
ok 1000 numbers
Test #6:
score: 0
Accepted
time: 2ms
memory: 4112kb
input:
1000 4 5 72227 53523 60356 75354 48348 59071 85117 86260 35140 27149 26706 84967 71598 76061 81453 53989 15316 82420 50695 46478 47536 10211 47703 57753 52396 25234 7015 28545 88953 3038 68077 40104 83546 75660 4206 97850 46721 49986 69628 79532 47269 93027 73722 38823 81502 9110 29754 24 19161 1699...
output:
188781625 762228616 136821592 674574163 347192262 485485871 629723820 280908647 588412565 725358221 863705098 659938578 242816623 893332458 843594911 548347865 837091341 189528539 686788524 27959019 161387564 209458902 58082579 541157908 634716980 370997719 711719499 222851922 266533026 468008815 12...
result:
ok 1000 numbers
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 4156kb
input:
1000 5 5 934 216 913 239 824 359 107 658 672 201 259 787 699 375 495 399 957 273 386 716 148 563 663 746 673 466 938 833 871 307 932 330 175 572 438 641 106 574 148 265 235 48 284 823 142 616 664 401 301 156 36 155 455 46 314 386 80 918 9 283 960 228 576 322 866 871 642 571 93 364 384 343 780 740 29...
output:
863298675 561844282 707253518 131162317 733366001 240959848 491331485 945999426 884095393 601677031 988828395 989129097 271230712 188285368 526283575 610318634 640662356 513566498 530541446 619910493 101188507 650095342 264873841 559625254 219249144 536317513 208763693 184423450 658893967 602055766 ...
result:
wrong answer 30th numbers differ - expected: '186389056', found: '602055766'