QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#420387 | #2819. 摆家具 | 300_205_205# | TL | 1747ms | 421936kb | C++20 | 2.9kb | 2024-05-24 17:01:12 | 2024-05-24 17:01:13 |
Judging History
answer
//#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define N 1000005
#define mod 998244353
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ls (rt<<1)
#define rs ((rt<<1)|1)
#define fi first
#define se second
#define INF 1e9
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
int qpow(int a,int b){
int res=1;
for(;b;b>>=1){
if(b&1) res=res*a%mod;
a=a*a%mod;
}
return res;
}
int fac[N],ifac[N];
int C(int n,int m){
if(m>n||m<0||n<0) return 0;
return fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
void init(){
fac[0]=1;
for(int i=1;i<N;i++) fac[i]=fac[i-1]*i%mod;
ifac[N-1]=qpow(fac[N-1],mod-2);
for(int i=N-2;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}
inline int lowbit(int x){return x&(-x);}
inline int read(){
int x=0,t=1;char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') t=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch-'0');
ch=getchar();
}
return x*t;
}
inline void write(int x){
if(x<0) putchar('-'),x=-x;
if(x>=10) write(x/10);
putchar(x%10+'0');
}
int T,n,k,q,p1[N],p2[N],val[N],B=sqrt(mod)+10,inc[25],sum[N],now[25],res[25];
int dp[N][21];
struct matrix{int a[21][21];}tmp,a0[40000],ab[40000];
matrix operator*(matrix a,matrix b){
matrix c;memset(c.a,0,sizeof(c.a));
for(int i=0;i<=k;i++)
for(int j=0;j<=k;j++)
for(int o=0;o<=k;o++)
(c.a[i][j]+=a.a[i][o]*b.a[o][j])%=mod;
return c;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>k>>q;init();
//k位,每位0~n
p1[0]=1;for(int i=1;i<=k;i++) p1[i]=p1[i-1]*n;
p2[0]=1;for(int i=1;i<=k;i++) p2[i]=p2[i-1]*(n-1);
for(int i=0;i<=k;i++)
inc[i]=C(k,i)*p2[i]%mod,inc[i]=qpow(inc[i],mod-2);
for(int i=0;i<=k;i++){
if(i) tmp.a[i-1][i]=i;
tmp.a[i][i]=i*(n-2)%mod;
if(i!=k) tmp.a[i+1][i]=(k-i)*(n-1)%mod;
}
a0[1]=tmp;
for(int i=2;i<=B;i++) a0[i]=a0[i-1]*tmp;
ab[1]=a0[B];
for(int i=2;i<=B;i++) ab[i]=ab[i-1]*a0[B];
for(int i=0;i<=k;i++) a0[0].a[i][i]=ab[0].a[i][i]=1;
int all=1;
for(int i=1;i<=k;i++) all=all*n;
for(int i=0;i<all;i++) cin>>val[i],dp[i][0]=val[i];
for(int i=0;i<k;i++){
for(int j=k;j>=1;j--){
memset(sum,0,sizeof(sum));
for(int l=0;l<all;l++){
int pos=l-p1[i]*((l/p1[i])%n);
(sum[pos]+=dp[l][j-1])%=mod;
}
for(int l=0;l<all;l++){
int pos=l-p1[i]*((l/p1[i])%n);
dp[l][j]=(dp[l][j]+sum[pos]+mod-dp[l][j-1])%mod;
}
}
}
int lst=1;
while(q--){
int a,b;cin>>a>>b;
b=b*lst%mod;
for(int i=0;i<=k;i++) now[i]=a0[b%B].a[i][0];
for(int i=0;i<=k;i++) res[i]=0;
for(int i=0;i<=k;i++)
for(int j=0;j<=k;j++){
int v=ab[b/B].a[i][j];
(res[i]+=v*now[j])%=mod;
}
int ans=0;
for(int i=0;i<=k;i++)(ans+=res[i]*inc[i]%mod*dp[a][i])%=mod;
//for(int i=0;i<=k;i++) cout<<res[i]<<" "<<dp[a][i]<<" "<<inc[i]<<endl;
cout<<ans<<endl;lst=ans;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 550ms
memory: 301096kb
input:
6 7 23333 691899807 511100503 969237388 938904792 350428599 320423686 227132681 288051232 833056445 128207711 81740114 850060462 194951182 130925016 505452669 304380595 703105541 640122112 75295756 128144693 482592240 835507949 68960843 807876145 6134269 259053259 386495729 193956365 370675670 12980...
output:
190581075 197794774 345498162 59688720 168669317 841717697 342906119 137414971 825722766 29575707 853971537 278001951 268532266 37403931 437460694 620208693 66609375 403688722 976391048 491806503 298322771 631646293 927418682 648947221 68582150 226201662 207241545 17375057 263100976 540120514 433099...
result:
ok 23333 lines
Test #2:
score: 0
Accepted
time: 1747ms
memory: 420240kb
input:
10 6 499992 883981029 424184611 390644163 186684863 174728805 352881784 953947952 773609716 907239584 791751597 444938530 461456743 385730847 148399228 774687506 9709242 68881950 559913618 909120969 567290547 274910682 127146223 18334763 679114303 509060537 406621577 596834508 415847390 750748687 69...
output:
893356346 460269203 739618263 575487556 823262857 959075468 442981064 379364003 520589980 408419264 962089959 532443198 457198012 936755450 707631444 639551012 501722307 54986538 947539125 293051047 736520294 145839901 669179979 385018500 178607686 73569962 457986293 912015195 183765686 794760523 77...
result:
ok 499992 lines
Test #3:
score: 0
Accepted
time: 1454ms
memory: 382912kb
input:
15 5 500000 505484351 497688716 546731680 964754919 196294896 617209569 555560108 91152824 603611039 403851027 608394993 262605748 565802956 744734397 31623673 595290933 617664042 655289027 31029383 427106733 830003904 614943018 971450634 87580932 542657216 939674620 536263049 542852153 618447940 71...
output:
979878232 502012447 837375524 648850473 372016965 88786781 438815378 350532799 135130633 639465431 315342261 17918128 255399473 659394908 630493926 323082621 927511589 215929363 335530238 618826645 379739184 19810887 399268915 103084315 217968568 457352471 24987165 330231636 873809029 114633697 2862...
result:
ok 500000 lines
Test #4:
score: 0
Accepted
time: 1096ms
memory: 410156kb
input:
31 4 500000 873132748 143861990 476370579 290413250 321978338 924143354 837842213 858068823 893643188 350393336 974299396 66468900 161847648 160755624 630177685 15786978 742472523 692563064 814267336 933743581 685556394 210699804 718255928 65125157 974700737 476917926 883144754 873388830 260036915 7...
output:
117268813 819018523 776768369 741209449 744498590 120071025 226984394 90007863 939423845 878313441 304691338 392220263 127581724 439314464 26862504 346663422 650004724 251278984 108796604 971079803 327255877 256973834 227173217 985548913 506828616 633681752 131186964 812774711 116108044 169648841 40...
result:
ok 500000 lines
Test #5:
score: 0
Accepted
time: 1160ms
memory: 420636kb
input:
100 3 500000 69501783 983926132 677774943 69763238 229978802 740941191 539402529 154743577 751966051 2646498 224715922 118063086 627921580 898461795 955831727 416453873 14778043 516566032 564752940 181778667 854451334 950970458 936033583 922684013 152424128 328311215 790981818 702141983 966264407 85...
output:
184621141 886327200 681090353 449056824 781618881 115181957 426499945 260260962 911237835 965376439 300419966 589424733 123229266 785625549 546029984 442034899 388267896 684458618 195809458 20009458 426509673 122152893 2104958 463059830 352181528 643342912 486348781 458867324 19039301 353204424 6039...
result:
ok 500000 lines
Test #6:
score: 0
Accepted
time: 846ms
memory: 421936kb
input:
1000 2 500000 483290026 77460592 332660242 106703469 434234061 455058920 556238357 24497230 922071773 467490309 577534517 169507551 728487110 708808551 529347050 871686307 577270581 10179512 594316766 667127175 563057402 852990097 207199337 955310144 731674888 467932878 392176687 821799278 969377355...
output:
368958893 157223722 292796988 642533231 159133366 284998940 65555601 251111003 783103389 154739003 575815496 790581708 709356018 408854640 372526412 308805425 614598882 571166795 580052186 718818280 56736587 815690398 91494865 197050725 109336354 374333046 374458971 858752081 833475651 585345655 499...
result:
ok 500000 lines
Test #7:
score: 0
Accepted
time: 526ms
memory: 421580kb
input:
1000000 1 500000 251055524 454201434 742507937 933949296 5497634 524473780 533949826 813658703 436744366 549681279 833659165 960901932 125155782 833291726 346494758 56508523 996923766 123565531 774148853 874417054 484068183 433006936 695931450 752399778 337593593 43594090 829258152 664530824 5594933...
output:
326771917 535904675 965793060 549465552 384143458 278039901 957870727 127785253 210029827 892986539 784268197 776296487 551595915 749545280 264971517 253922166 789378018 185371966 568293778 272220006 322113820 429616722 602408789 912040965 171539430 943059113 485799881 852599179 773978550 869366175 ...
result:
ok 500000 lines
Test #8:
score: 0
Accepted
time: 620ms
memory: 297748kb
input:
8 6 66666 762632409 278781514 983938354 215161563 825597216 334484655 896602072 349664404 791855251 519549984 535486218 722755687 976326824 780635505 740436130 731964947 676528034 358069017 168477195 921166389 469310971 305642123 903617163 278297809 268861284 87258643 487466490 446331721 887038434 1...
output:
435885311 791730460 394640664 75649208 641167408 622645423 585865614 673979813 215664794 946211062 813726822 173088040 382435698 736541474 742744192 129571340 355179929 982890533 370134926 164867173 403374726 393851117 898586967 24557503 469648925 716601758 484716413 925321022 886807109 332801791 40...
result:
ok 66666 lines
Test #9:
score: 0
Accepted
time: 132ms
memory: 256404kb
input:
12 4 55555 197178262 578999644 333173795 551118586 317399521 499956238 822139685 581307933 167129094 564412175 704862130 607776171 751153237 939551291 182286053 432731777 528429591 745229393 733266093 605324803 41983117 120383567 620780688 608752835 931257346 200024433 241498351 228791449 580080365 ...
output:
661082746 815441729 100762693 294477597 736004158 439025524 879104083 292739355 43371968 866655117 274828007 545033662 715290768 794583370 636756659 491641439 872639006 848225686 971139705 674984253 78007132 88277942 644385137 672152403 707666118 220936700 458557694 8298591 499614459 91242274 778977...
result:
ok 55555 lines
Test #10:
score: 0
Accepted
time: 252ms
memory: 262100kb
input:
233 2 233333 268358199 873653363 469164977 484799852 130172856 468808868 855128475 884288087 813589312 418175909 160012718 482438225 546274631 681769076 939719128 910906006 150691738 170063927 712952591 433792439 459493770 1906569 779711173 261615079 761652883 456069570 312579657 340663490 844762847...
output:
735261715 695986226 342581903 89591047 982713738 126272926 530843418 830949156 695151160 460788630 199212163 681916027 306210097 214205027 872146063 255204872 570801958 374890385 899215195 250476623 519963882 217276010 344171156 458149854 507840400 378333793 968555287 360821807 496932371 804688371 5...
result:
ok 233333 lines
Test #11:
score: -100
Time Limit Exceeded
input:
2 19 500000 713448041 15755846 961811667 280573995 386148277 964323207 842485042 947749487 42983063 917443625 305236230 111429944 181915829 784845875 650459231 761824955 348455354 607083113 555660898 307955183 457192498 45086306 297195265 593232944 6222701 189812219 576174218 922820203 498943822 842...