QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#311733 | #1831. Bruteforce | CrayonIsGay | WA | 2761ms | 304916kb | C++98 | 7.7kb | 2024-01-22 18:20:48 | 2024-01-22 18:20:50 |
Judging History
answer
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,tune=native")
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define pii pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
const ll N = 2e5+100;
const ll INF = (ll)1e18;
const ll MOD = 998244353;
inline ll read(){
ll ret=0,f=1;char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') f*=-1;
ch=getchar();
}
while(isdigit(ch)){
ret=(ret<<3)+(ret<<1)+ch-'0';
ch=getchar();
}
return ret*f;
}
ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
ll kpow(ll a,ll b,ll mod){
ll ret=1,base=a%mod;while(b){if(b&1) ret=ret*base%mod;base=base*base%mod;b>>=1;}return ret;
}
inline ll upd(ll x){return (x%MOD+MOD)%MOD;}
ll C[10][10];
inline ll get_d(ll k,ll c,ll w){
return C[k][c]*kpow(w,k-c,MOD);
}
ll n,m,k,W,a[N];
const ll V = 1e5+2;
struct segment_tree0{
ll mod;
int cnt[N*4],sum[N*4],sum_k[6][N*4];
int tg[N*4];
segment_tree0(){memset(cnt,0,sizeof(cnt));memset(sum,0,sizeof(sum));memset(sum_k,0,sizeof(sum_k));memset(tg,0,sizeof(tg));}
inline void push_up(int rt){
sum[rt]=upd(sum[rt<<1]+sum[rt<<1|1]);
for(int i=0;i<=k;++i)
sum_k[i][rt]=upd(sum_k[i][rt<<1]+sum_k[i][rt<<1|1]);
cnt[rt]=cnt[rt<<1]+cnt[rt<<1|1];
}
inline void modify(int rt,int v){
tg[rt]+=v;
for(int i=k;i>=0;i--)
for(int j=i-1;j>=0;j--)
sum_k[i][rt]=upd(sum_k[i][rt]+1ll*sum_k[j][rt]*get_d(i,j,v));
sum[rt]=sum_k[k][rt];
}
inline void push_down(int rt){
if(tg[rt]!=0){
modify(rt<<1,tg[rt]);
modify(rt<<1|1,tg[rt]);
tg[rt]=0;
}
}
inline int query_sz(int rt,int l,int r,int idx){
if(r<=idx) return cnt[rt];
if(l>idx) return 0;
int mid=(l+r)>>1;
return query_sz(rt<<1,l,mid,idx)+query_sz(rt<<1|1,mid+1,r,idx);
}
inline void update_v(int rt,int l,int r,int w,int c){
if(r<w||l>w) return;
if(l==r){
if(c==1){
ll id=query_sz(1,0,V,w)+1;
cnt[rt]++;
// cout<<"id="<<id<<endl;
for(ll i=0;i<=k;++i)
sum_k[i][rt]=upd(1ll*sum_k[i][rt]+1ll*w*kpow(id,i,mod)%mod);
}else{
ll id=query_sz(1,0,V,w);
cnt[rt]--;
for(ll i=0;i<=k;++i)
sum_k[i][rt]=upd(1ll*sum_k[i][rt]-1ll*w*kpow(id,i,mod)%mod);
}
sum[rt]=sum_k[k][rt];
return ;
}
int mid=l+r>>1;
push_down(rt);
update_v(rt<<1,l,mid,w,c);
update_v(rt<<1|1,mid+1,r,w,c);
push_up(rt);
}
inline void update_i(int rt,int l,int r,int ql,int qr,int v){
if(r<ql||l>qr) return;
if(ql<=l&&r<=qr){
if(v==1){
for(int i=k;i>=0;i--)
for(int j=i-1;j>=0;j--)
sum_k[i][rt]=upd(1ll*sum_k[i][rt]+1ll*sum_k[j][rt]*get_d(i,j,v));
}else{
for(int i=k;i>=0;i--)
for(int j=i-1;j>=0;j--)
sum_k[i][rt]=upd(1ll*sum_k[i][rt]+1ll*sum_k[j][rt]*get_d(i,j,v));
}
sum[rt]=sum_k[k][rt];
tg[rt]+=v;
return ;
}
int mid=(l+r)>>1;
push_down(rt);
update_i(rt<<1,l,mid,ql,qr,v);
update_i(rt<<1|1,mid+1,r,ql,qr,v);
push_up(rt);
}
}sg0;
ll kpw[20][20];
struct segment_tree1{
int cnt[N*4],sum[N*4],sum_k[6][6][N*4];
int tg[N*4];
segment_tree1(){memset(cnt,0,sizeof(cnt));memset(sum,0,sizeof(sum));memset(sum_k,0,sizeof(sum_k));memset(tg,0,sizeof(tg));}
inline void push_up(int rt){
sum[rt]=upd(sum[rt<<1]+sum[rt<<1|1]);
for(int i=0;i<W;++i)
for(int j=0;j<W;++j)
sum_k[i][j][rt]=upd(sum_k[i][j][rt<<1]+sum_k[i][j][rt<<1|1]);
cnt[rt]=cnt[rt<<1]+cnt[rt<<1|1];
}
inline void modify(int rt,int v){
v=(v%W+W)%W;
ll ret[5][5];
sum[rt]=0;
for(int j=0;j<W;++j){
for(int i=0;i<W;++i)
ret[j][i]=sum_k[j][(i-v+W*2)%W][rt];
for(int i=0;i<W;++i)
sum_k[j][i][rt]=ret[j][i];
for(int i=0;i<W;++i)
sum[rt]=upd(sum[rt]+1ll*j*kpw[i][k]%W*sum_k[j][i][rt]%MOD);
}
}
inline void push_down(int rt){
if(tg[rt]!=0){
modify(rt<<1,tg[rt]);
modify(rt<<1|1,tg[rt]);
tg[rt<<1]+=tg[rt];tg[rt<<1|1]+=tg[rt];
tg[rt]=0;
}
}
inline ll query_sz(int rt,int l,int r,int idx){
if(r<=idx) return cnt[rt];
if(l>idx) return 0;
int mid=(l+r)>>1;
return query_sz(rt<<1,l,mid,idx)+query_sz(rt<<1|1,mid+1,r,idx);
}
inline void update_v(int rt,int l,int r,int w,int c){
if(r<w||l>w) return;
if(l==r){
if(c==1){
ll id=query_sz(1,0,V,w)+1;
cnt[rt]++;
sum_k[w%W][id%W][rt]=upd(sum_k[w%W][id%W][rt]+1);
}else{
ll id=query_sz(1,0,V,w);
cnt[rt]--;
sum_k[w%W][id%W][rt]=upd(sum_k[w%W][id%W][rt]-1);
}
sum[rt]=0;
for(int j=0;j<W;++j)
for(int i=0;i<W;++i)
sum[rt]=upd(sum[rt]+1ll*j*kpw[i][k]%W*sum_k[j][i][rt]%MOD);
return ;
}
int mid=l+r>>1;
push_down(rt);
update_v(rt<<1,l,mid,w,c);
update_v(rt<<1|1,mid+1,r,w,c);
push_up(rt);
}
inline void update_i(int rt,int l,int r,int ql,int qr,int v){
if(r<ql||l>qr) return;
if(ql<=l&&r<=qr){
modify(rt,v);
tg[rt]+=v;
return ;
}
int mid=(l+r)>>1;
push_down(rt);
update_i(rt<<1,l,mid,ql,qr,v);
update_i(rt<<1|1,mid+1,r,ql,qr,v);
push_up(rt);
}
}sg1;
void multi_test(){
for(int i=0;i<=6;++i){
C[i][0]=C[i][i]=1;
for(int j=1;j<=i;++j)
C[i][j]=C[i-1][j-1]+C[i-1][j];
}
n=read(),k=read(),W=read();
for(int i=0;i<=10;++i)
for(int j=0;j<=10;++j)
kpw[i][j]=kpow(i,j,W);
sg0.mod=998244353;//sg1.mod=W;
for(int i=1;i<=n;++i){
a[i]=read();
sg0.update_v(1,0,V,a[i],1);
sg0.update_i(1,0,V,a[i]+1,V,1);
sg1.update_v(1,0,V,a[i],1);
sg1.update_i(1,0,V,a[i]+1,V,1);
}
ll q=read();
while(q--){
ll pos=read(),x=read();
sg0.update_v(1,0,V,a[pos],-1);
sg0.update_i(1,0,V,a[pos]+1,V,-1);
sg0.update_v(1,0,V,x,1);
sg0.update_i(1,0,V,x+1,V,1);
// cout<<"*"<<sg0.sum[1]<<endl;
sg1.update_v(1,0,V,a[pos],-1);
sg1.update_i(1,0,V,a[pos]+1,V,-1);
sg1.update_v(1,0,V,x,1);
sg1.update_i(1,0,V,x+1,V,1);
// cout<<"&"<<sg1.sum[1]<<endl;
printf("%lld\n",1ll*upd(sg0.sum[1]-sg1.sum[1])*kpow(W,MOD-2,MOD)%MOD);
a[pos]=x;
}
return ;
}
/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts
5. long long
6. corner case like n=0,1,inf or n=m
7. fileio in some oi-contest
8. module on time
9. the number of a same divisor in a math problem
10. multi-information and queries
*/
signed main(){
ll T=1;
while(T--) multi_test();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 8ms
memory: 304012kb
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: 4ms
memory: 304012kb
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: 303992kb
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: 15ms
memory: 303988kb
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: 56ms
memory: 303936kb
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: 63ms
memory: 303956kb
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: 0
Accepted
time: 39ms
memory: 304000kb
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 186389056 ...
result:
ok 1000 numbers
Test #8:
score: -100
Wrong Answer
time: 2761ms
memory: 304916kb
input:
100000 5 5 80 589 96 690 525 951 787 896 916 752 55 923 620 300 287 174 450 222 758 283 713 795 782 655 93 795 249 236 692 545 438 356 63 139 441 943 871 187 810 563 634 234 148 160 911 114 487 521 180 416 657 301 35 67 122 338 190 673 630 712 719 216 976 883 51 651 936 531 679 580 804 173 456 815 7...
output:
852219121 254267604 693002652 517948565 701339493 64241810 911179889 759514207 770587230 109897573 378474201 554446739 529017469 785659324 588042088 454266476 292155761 288943621 487750680 405648395 781021779 623648635 8424191 184740135 478202042 513477192 848771227 478799713 519793212 438525861 428...
result:
wrong answer 1st numbers differ - expected: '334846524', found: '852219121'