QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#883806 | #8822. Guess The Sequence 2 | songke | WA | 1ms | 12012kb | C++14 | 1.4kb | 2025-02-05 19:04:15 | 2025-02-05 19:04:19 |
Judging History
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;
F(cc,1,n)
{
int i=pos[cc];
dp[cc]=dp[0];
dp[0]=dp[0]*(qpow(2,(ll)(i-L[i])*(R[i]-i))-1)%mod;
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;
dp[a[j]]=((ll)dp[a[j]]*(qpow(2,(ll)(i-j)*(R[i]-i))-1))%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;
dp[a[j]]=((ll)dp[a[j]]*(qpow(2,(ll)(j-i)*(i-L[i]))-1))%mod;
}
F(j,1,cc-1)if(pos[j]<L[i]||pos[j]>R[i])dp[j]=(ll)dp[j]*(qpow(2,(i-L[i])*(R[i]-i))-1)%mod;
}
int ans=0;
F(i,0,n)
{
ans+=dp[i];
if(ans>=mod)ans-=mod;
}
cout<<ans<<'\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11880kb
input:
2 1 2
output:
6
result:
ok "6"
Test #2:
score: 0
Accepted
time: 1ms
memory: 12012kb
input:
4 1 4 2 3
output:
532
result:
ok "532"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 11876kb
input:
10 10 1 3 6 8 5 7 4 2 9
output:
249703394
result:
wrong answer 1st words differ - expected: '148069845', found: '249703394'