QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#659783 | #9477. Topological Sort | ucup-team134# | WA | 0ms | 4216kb | C++17 | 1.4kb | 2024-10-19 21:59:45 | 2024-10-19 21:59:46 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128
using namespace std;
mt19937 rng(time(NULL));
const int mod=998244353;
int add(int a,int b){
a+=b;
if(a>=mod)
a-=mod;
return a;
}
int sub(int a,int b){
a-=b;
if(a<0)
a+=mod;
return a;
}
int mul(int a,int b){
return (long long)a*b%mod;
}
int pwrmod(int x,ll k){
int ans=1;
for(;k;k>>=1,x=mul(x,x))
if(k&1)
ans=mul(ans,x);
return ans;
}
int inv2=pwrmod(2,mod-2);
int main()
{
ios;
int n;
cin >> n;
vector<int> p(n);
vector<int> gde(n+1);
for(int i=0;i<n;i++){
int x;
cin >> x;
p[i]=x;
gde[x]=i;
}
vector<int> pre(n);
set<int> t;
for(int i=n-1;i>=0;i--){
int x=p[i];
int c=0;
while(sz(t)&&(*t.begin())<x){
int my=*t.begin();
t.erase(t.begin());
c++;
pre[gde[my]]=c;
}
t.insert(x);
}
int ans=1;
for(int i=0;i<n;i++){
if(pre[i]==0){
ans=mul(ans,pwrmod(2,i));
continue;
}
int my=sub(sub(pwrmod(2,i),1),sub(pwrmod(2,i-pre[i]),1));
ans=mul(ans,my);
}
printf("%i\n",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
input:
3 1 3 2
output:
4
result:
ok "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
5 1 2 3 4 5
output:
1024
result:
ok "1024"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
6 4 2 1 5 6 3
output:
4096
result:
ok "4096"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 4216kb
input:
492 397 486 227 395 58 452 172 216 130 181 268 482 85 209 365 104 373 90 260 326 252 96 267 106 102 398 441 41 292 314 12 78 242 353 153 424 179 86 299 228 54 390 73 465 396 349 4 10 451 99 342 250 391 6 323 197 159 47 136 473 392 77 125 362 418 255 291 13 238 339 8 28 413 121 384 157 152 23 221 305...
output:
704006309
result:
wrong answer 1st words differ - expected: '73428942', found: '704006309'