QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#692629 | #9477. Topological Sort | Tggdb# | WA | 3ms | 26476kb | C++20 | 1.4kb | 2024-10-31 14:49:16 | 2024-10-31 14:49:18 |
Judging History
answer
#include<stdio.h>
#include<iostream>
#include<algorithm>
#define inf 0X7fffffff
#define int long long
using namespace std;
const int N=2e6+9;
const int p=998244353;
int read(int &x){
int dat=0,oko=1;char chc=getchar();
while(chc<'0'||chc>'9'){if(chc=='-')oko=-1;chc=getchar();}
while(chc>='0'&&chc<='9'){dat=dat*10+chc-'0';chc=getchar();}
x=dat*oko;return x;
}int n,a[N],head[N],siz[N],tot,ans,st[N];
int tree[N],sum;
int lowbit(int x){return x&(-x);}
void add(int x){
while(x<=n){
tree[x]++;
x+=lowbit(x);
}
}int query(int x){
int res=0;
while(x){
res+=tree[x];
x-=lowbit(x);
}return res;
}int quick(int x,int k){
int res=1,base=x;
while(k){
if(k&1)res=res*base%p;
base=base*base%p;k>>=1;
}return res;
}int self(int x){
x--;if(x)x--;
return (((x+1)*x)>>1)%p;
}signed main(){
read(n);st[0]=1;ans=1;
for(int i=1;i<N;i++)st[i]=(st[i-1]<<1);
for(int i=1;i<=n;i++){
read(a[i]);
if(a[i]>a[i-1]){
head[++tot]=a[i];
siz[tot]=1;
}else siz[tot]++;
}for(int i=tot;i>=1;i--){
int temp=query(head[i]);
ans=ans*quick(st[siz[i]]-1,temp)%p;
ans=ans*quick(st[sum-temp],siz[i]);
ans=ans*st[self(siz[i])];
sum+=siz[i];add(head[i]);
}printf("%lld\n",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 24368kb
input:
3 1 3 2
output:
4
result:
ok "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 26476kb
input:
5 1 2 3 4 5
output:
1024
result:
ok "1024"
Test #3:
score: 0
Accepted
time: 0ms
memory: 24328kb
input:
6 4 2 1 5 6 3
output:
4096
result:
ok "4096"
Test #4:
score: -100
Wrong Answer
time: 3ms
memory: 26408kb
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:
0
result:
wrong answer 1st words differ - expected: '73428942', found: '0'