QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#528752 | #8822. Guess The Sequence 2 | zeq2021 | AC ✓ | 658ms | 36780kb | C++14 | 4.0kb | 2024-08-23 20:53:31 | 2024-08-23 20:53:31 |
Judging History
answer
/*
* /$$ /$$
* |__/ |__/
* /$$$$$$$$ /$$ /$$$$$$$$ /$$ /$$$$$$
* |____ /$$/| $$|____ /$$/| $$ /$$__ $$
* /$$$$/ | $$ /$$$$/ | $$| $$ \ $$
* /$$__/ | $$ /$$__/ | $$| $$ | $$
* /$$$$$$$$| $$ /$$$$$$$$| $$| $$$$$$$
* |________/|__/|________/|__/ \____ $$
* | $$
* | $$
* |__/
*/
//hj23308保佑我
//Missile保佑我
/*
* 醒了在梦里挣扎,不觉黯淡了朝霞
*/
/*
* 我很高兴你没有忘了我,但是我现在更希望你已经忘了我了。
* 希望在你的记忆中,我只是尘土一撮,从你的全世界路过,然后四散飞扬不留下一点痕迹,而你要不回头的往前走。
* 我更希望我只是从你的全世界路过,只是路过
*/
/*
* 只是我在十字路口守了太久,守到黄沙如雨掩埋一切痕迹,才发现自己等的人已经离开了。
*/
/*
* 听我的 别回头 回头就可能会泪流满面,会被黄沙掩埋,所以即使痛苦也要向前走
*/
/*
* 我听到了「天行健」的回响,这是一个伟大斗士的不息自强;
* 我听到了「破万法」的回响,这是一个黑道打手的守护欲望;
* 我看见了「生生不息」的激荡,这是一个骗子的伟大乐章!
*/
/*
* 我用虚假的面具照顾着细腻的感情;
* 我以华丽的衣物下藏着腐烂的血肉;
* 当我摘下面具,褪去衣物,即便是我最亲近的人,也无法直视我
*/
#include<bits/stdc++.h>
using namespace std;
const int B=(1<<16);
const int MAXN=5e5+5;
const int MOD=998244353;
int T,n;
long long ans,f[MAXN];
int a[MAXN],site[MAXN],prt[MAXN],l[MAXN],r[MAXN];
stack<int>q;
long long sumA[MAXN],sumB[MAXN];
long long Sum[MAXN],iSum[MAXN],pSum[MAXN];
long long qpow(long long u,long long k)
{
long long Ans=1;
while(k) {
if(k&1) Ans=Ans*u%MOD;
u=u*u%MOD;
k/=2;
}
return Ans;
}
void Init()
{
sumA[0]=sumB[0]=1;
long long K=qpow(2,B);
for(int i=1;i<B;i++) {
sumA[i]=sumA[i-1]*2%MOD;
sumB[i]=sumB[i-1]*K%MOD;
}
}
long long tpow(long long k)
{
k%=(MOD-1);
return sumB[k>>16]*sumA[k&65535]%MOD;
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// cin>>T;
Init();
// while(T--) {
ans=0;
cin>>n;
for(int i=1;i<=n;i++) {
prt[i]=0;
l[i]=0,r[i]=n+1;
}
while(!q.empty()) q.pop();
for(int i=1;i<=n;i++) {
cin>>a[i];
site[a[i]]=i;
int last=0;
while(!q.empty()&&a[i]>a[q.top()]) {
r[q.top()]=i;
last=q.top();
q.pop();
}
if(last) {
prt[last]=i;
}
if(!q.empty()) {
prt[i]=l[i]=q.top();
}
q.emplace(i);
}
// for(int i=1;i<=n;i++) {
// cout<<i<<" debabashi "<<prt[i]<<"\n";
// }
// cout<<"tpow : "<<tpow(9)<<"\n";
for(int i=1;i<=n;i++) {
f[i]=0;
Sum[i]=tpow(1ll*(i-l[i])*(r[i]-i))-1;
iSum[i]=qpow(Sum[i],MOD-2);
}
pSum[0]=1;
// cerr<<"a?\n";
for(int i=1;i<=n;i++) {
pSum[i]=pSum[i-1]*Sum[site[i]]%MOD;
}
f[0]=1;
for(int i=1;i<=n;i++) {
int u=site[i],x=u;
f[i]=(f[i]+f[i-1]*Sum[u])%MOD;
// cout<<"Sum["<<i<<"] : "<<Sum[u]<<"\n";
// cout<<"f["<<i<<"] : "<<f[i]<<"\n";
long long res=qpow(pSum[i],MOD-2);
while(prt[x]) {
x=prt[x];
res=res*iSum[x]%MOD;
if(u<x) {
res=res*(tpow(1ll*(x-u)*(r[x]-x))-1)%MOD;
}
else res=res*(tpow(1ll*(x-l[x])*(u-x))-1)%MOD;
int j=a[x];
// cout<<"j : "<<j<<"\n";
long long mul=res*pSum[j]%MOD;
if(u<x) {
mul=mul*(tpow(1ll*(u-l[x])*(r[x]-x))-1)%MOD;
}
else mul=mul*(tpow(1ll*(x-l[x])*(r[x]-u))-1)%MOD;
f[j]=(f[j]+mul*f[i-1])%MOD;
}
// cout<<"AddC : "<<f[i-1]*pSum[n]%MOD*res%MOD<<"\n";
ans=(ans+f[i-1]*pSum[n]%MOD*res%MOD)%MOD;
// cout<<"f["<<i<<"] : "<<f[i]<<"\n";
// cout<<"----------------------------------------\n";
}
ans=(ans+f[n])%MOD;
cout<<ans<<"\n";
// }
return 0;
}
/*
input:
1
3
3 1 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 24056kb
input:
2 1 2
output:
6
result:
ok "6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 24040kb
input:
4 1 4 2 3
output:
532
result:
ok "532"
Test #3:
score: 0
Accepted
time: 0ms
memory: 24052kb
input:
10 10 1 3 6 8 5 7 4 2 9
output:
148069845
result:
ok "148069845"
Test #4:
score: 0
Accepted
time: 0ms
memory: 28136kb
input:
10 6 1 4 2 9 5 7 3 8 10
output:
478415758
result:
ok "478415758"
Test #5:
score: 0
Accepted
time: 0ms
memory: 24144kb
input:
100 100 92 62 88 12 7 43 31 19 72 51 44 10 76 93 17 37 6 96 55 45 68 81 34 18 91 56 39 20 59 75 77 27 2 64 84 66 3 69 89 50 54 29 95 16 25 32 14 21 33 24 87 97 80 13 94 9 63 85 40 15 28 49 26 41 61 52 47 74 71 35 42 22 57 8 99 58 1 86 82 4 98 46 5 23 38 67 60 70 73 83 65 53 11 79 90 48 36 78 30
output:
924190604
result:
ok "924190604"
Test #6:
score: 0
Accepted
time: 4ms
memory: 24048kb
input:
100 65 83 68 87 21 80 60 20 45 64 26 34 56 12 50 18 97 5 71 58 32 31 76 59 39 7 82 62 1 4 19 41 9 55 14 81 61 23 96 8 88 67 95 99 33 35 24 70 84 13 17 78 53 94 22 11 44 86 2 54 6 40 36 57 79 25 72 16 47 100 51 46 38 77 29 52 37 63 98 30 93 69 28 75 3 91 73 42 90 15 10 92 85 27 49 66 74 43 48 89
output:
629026282
result:
ok "629026282"
Test #7:
score: 0
Accepted
time: 4ms
memory: 22008kb
input:
1000 921 368 121 810 357 118 209 562 91 506 805 188 586 223 281 796 402 772 998 983 646 854 676 226 871 392 200 323 410 242 991 740 340 337 577 38 325 453 396 932 365 501 712 478 260 92 763 232 668 813 844 426 547 285 715 935 797 471 123 467 526 643 748 839 451 605 762 168 890 356 386 719 5 164 766 ...
output:
940570820
result:
ok "940570820"
Test #8:
score: 0
Accepted
time: 5ms
memory: 26168kb
input:
1000 518 290 738 554 997 691 785 430 138 658 745 601 892 967 32 189 633 334 437 552 505 1 333 503 551 584 420 454 319 968 489 626 661 104 853 533 930 792 679 281 932 452 674 616 60 566 19 363 783 18 416 409 964 65 485 223 714 863 354 103 75 85 246 513 975 950 263 181 940 262 306 837 749 51 522 852 9...
output:
247069652
result:
ok "247069652"
Test #9:
score: 0
Accepted
time: 6ms
memory: 24124kb
input:
10000 9160 2607 2915 5867 4485 3215 6892 1868 9592 9215 4783 9840 9987 4520 2231 1530 8302 3943 618 9313 2087 1730 9115 9093 8426 744 584 7370 4415 34 4164 9394 4761 8732 193 2423 5313 2270 882 8951 1374 1907 9641 157 9681 124 5931 310 4418 4417 7298 8531 7986 522 7266 4472 2629 4686 7981 1334 5191 ...
output:
47093015
result:
ok "47093015"
Test #10:
score: 0
Accepted
time: 5ms
memory: 24392kb
input:
10000 5143 2984 9140 1647 9965 8331 5379 9660 8573 5491 1244 9735 31 1002 9003 7415 8212 4378 3566 2566 5546 2851 5396 2376 7707 2403 8181 1559 9918 563 4056 755 5447 1833 4271 3743 7794 7376 5075 5768 6501 7997 8437 2603 945 9776 5817 8744 20 434 9053 9162 6553 7929 3557 2384 10 3315 1209 9338 3717...
output:
426871590
result:
ok "426871590"
Test #11:
score: 0
Accepted
time: 77ms
memory: 26936kb
input:
100000 39438 53660 60245 20924 38669 24920 82129 49576 26576 87100 63645 98134 42814 77737 29788 70204 63290 69851 71187 76515 86622 63469 9284 48463 52926 76958 71097 69312 13627 89667 87192 6484 55986 81456 430 9270 45522 20083 62818 34655 5637 34892 6139 59908 45759 45035 99727 45374 93098 17644 ...
output:
561179335
result:
ok "561179335"
Test #12:
score: 0
Accepted
time: 87ms
memory: 30328kb
input:
100000 69632 70213 62832 61462 93551 36031 719 77464 16148 16597 26921 87433 59472 86552 92994 62155 57393 68496 65170 21852 30870 43896 83590 5562 75555 6634 16880 44746 14941 92534 76504 15607 1302 87672 45010 59014 42460 69670 27526 30086 41442 91923 88918 96315 38033 30901 14215 81768 26981 2592...
output:
160617700
result:
ok "160617700"
Test #13:
score: 0
Accepted
time: 658ms
memory: 34724kb
input:
500000 337916 152666 294610 290025 160899 257977 33747 153161 310527 441672 134171 160047 481704 63841 464145 12970 487275 253018 426843 1204 287974 438268 190860 299013 429984 438099 398578 221797 280426 258761 467065 482656 124226 454112 348923 221379 410400 112612 192090 457442 306912 213559 4812...
output:
570993983
result:
ok "570993983"
Test #14:
score: 0
Accepted
time: 626ms
memory: 32616kb
input:
500000 155562 90788 79051 102013 302335 425254 434627 156968 95807 390978 11853 438208 136967 331048 223486 319357 65255 129024 228173 335925 252878 88448 242711 215448 157161 257149 421899 439300 93619 343572 318046 490240 125168 201633 177194 397491 237455 166716 38325 237792 225568 7504 428801 20...
output:
730242640
result:
ok "730242640"
Test #15:
score: 0
Accepted
time: 595ms
memory: 32736kb
input:
500000 308297 298852 264435 484009 171596 173525 283848 209183 380711 491217 399826 356745 9866 179772 433696 257485 134699 30546 406801 139428 66519 429305 4851 359775 69657 286076 341688 365642 246826 232536 171594 37427 162628 91497 495667 404391 147238 250869 112959 159855 122671 256003 447656 4...
output:
443508703
result:
ok "443508703"
Test #16:
score: 0
Accepted
time: 600ms
memory: 36768kb
input:
500000 99093 335028 114719 133498 451141 353905 346145 264098 108696 405930 385203 448134 224024 164676 405846 313682 69416 406155 184313 203834 236290 337524 460633 96422 369135 407662 249471 449429 295519 308726 31246 417313 125111 105084 320461 129781 282417 495795 314881 171345 355738 370041 293...
output:
14462161
result:
ok "14462161"
Test #17:
score: 0
Accepted
time: 619ms
memory: 36780kb
input:
500000 398965 218097 42563 208172 157820 284061 461436 356687 201206 386568 294709 123266 414745 405408 354716 250833 134060 242952 186622 326873 181280 428981 331788 139893 151181 143842 335220 178876 72548 261543 376615 263201 174053 436234 247969 29532 245878 424942 429312 43458 164567 161871 268...
output:
38573556
result:
ok "38573556"
Extra Test:
score: 0
Extra Test Passed