QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#668129 | #9477. Topological Sort | huaxiamengjin | WA | 1ms | 5712kb | C++14 | 562b | 2024-10-23 11:39:11 | 2024-10-23 11:39:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int NN=998244353;
int n,a[200200],ans=1;
int b[200200];
set<int>s;
int p[200200];
signed main(){
cin>>n;
p[0]=1;
for (int i=1;i<=n;i++)
p[i]=p[i-1]*2%NN;
for (int i=1;i<=n;i++)
cin>>a[i],b[a[i]]=i;
for (int i=n;i;i--){
auto it=s.lower_bound(b[i]);
if(it!=s.begin()){
it--;
ans=ans*(p[b[i]-1]-p[(*it)-1])%NN;
}else ans=ans*p[b[i]-1]%NN;
s.insert(b[i]);
}
cout<<ans<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5688kb
input:
3 1 3 2
output:
4
result:
ok "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5668kb
input:
5 1 2 3 4 5
output:
1024
result:
ok "1024"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5632kb
input:
6 4 2 1 5 6 3
output:
4096
result:
ok "4096"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5712kb
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:
-924815411
result:
wrong answer 1st words differ - expected: '73428942', found: '-924815411'