QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883823#8822. Guess The Sequence 2dxbtTL 449ms11924kbC++141.4kb2025-02-05 19:11:512025-02-05 19:11:52

Judging History

This is the latest submission verdict.

  • [2025-02-05 19:11:52]
  • Judged
  • Verdict: TL
  • Time: 449ms
  • Memory: 11924kb
  • [2025-02-05 19:11:51]
  • Submitted

answer

#include<bits/stdc++.h>
#define F(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
#define G(i,l,r) for(int i=(l),i##end=(r);i>=i##end;--i)
#define x first
#define y second
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define ep emplace_back
using namespace std;
typedef long long ll;
constexpr int N=5e5,mod=998244353;
int n,a[N+9];
int L[N+9],R[N+9],stk[N+9],dp[N+9],pos[N+9];
int qpow(int x,int y)
{
	int res=1;
	for(;y;y>>=1,x=(ll)x*x%mod)if(y&1)res=(ll)res*x%mod;
	return res;
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	F(i,1,n)cin>>a[i],pos[a[i]]=i;
	int top=0;
	F(i,1,n)
	{
		while(top&&a[stk[top]]<a[i])
			R[stk[top--]]=i;
		L[i]=stk[top];
		stk[++top]=i;
	}
	F(i,1,top)R[stk[i]]=n+1;
	dp[0]=1;int pp=1;
	F(cc,1,n)
	{
		int i=pos[cc];int add=(qpow(2,(ll)(i-L[i])*(R[i]-i))-1);int inv=qpow(add,mod-2);
		dp[cc]=(ll)dp[0]*inv%mod;pp=(ll)pp*add%mod;
		dp[0]=(ll)dp[0];
		F(j,L[i]+1,i-1)
		{
			dp[0]=(dp[0]+(ll)dp[a[j]]*(qpow(2,(j-L[i])*(R[i]-i))-1)%mod*(qpow(2,(i-j)*(R[i]-i))-1)%mod*inv)%mod;
			dp[a[j]]=((ll)dp[a[j]]*(qpow(2,(ll)(i-j)*(R[i]-i))-1)%mod*inv)%mod;
		}
		F(j,i+1,R[i]-1)
		{
			dp[0]=(dp[0]+(ll)dp[a[j]]*(qpow(2,(R[i]-j)*(i-L[i]))-1)%mod*(qpow(2,(j-i)*(i-L[i]))-1)%mod*inv)%mod;
			dp[a[j]]=((ll)dp[a[j]]*(qpow(2,(ll)(j-i)*(i-L[i]))-1)%mod*inv)%mod;
		}
	}
	int ans=0;
	F(i,0,n)
	{
		ans+=dp[i];
		if(ans>=mod)ans-=mod;
	}
	cout<<(ll)ans*pp%mod<<'\n';
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 9836kb

input:

2
1 2

output:

6

result:

ok "6"

Test #2:

score: 0
Accepted
time: 0ms
memory: 11876kb

input:

4
1 4 2 3

output:

532

result:

ok "532"

Test #3:

score: 0
Accepted
time: 1ms
memory: 11876kb

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: 9836kb

input:

10
6 1 4 2 9 5 7 3 8 10

output:

478415758

result:

ok "478415758"

Test #5:

score: 0
Accepted
time: 1ms
memory: 9836kb

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: 1ms
memory: 11880kb

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: 2ms
memory: 9852kb

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: 2ms
memory: 9800kb

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: 26ms
memory: 11920kb

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: 26ms
memory: 11924kb

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: 449ms
memory: 10420kb

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: -100
Time Limit Exceeded

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:


result: