QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692890#9477. Topological SortTggdb#TL 7ms26476kbC++201.4kb2024-10-31 15:10:352024-10-31 15:10:47

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 15:10:47]
  • 评测
  • 测评结果:TL
  • 用时:7ms
  • 内存:26476kb
  • [2024-10-31 15:10:35]
  • 提交

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,int val){
    while(x<=n){
        tree[x]+=val;
        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);
}
signed main(){
    read(n);st[0]=1;ans=1;
    for(int i=1;i<N;i++)st[i]=(st[i-1]<<1)%p;
    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])%p;
        ans=ans*quick(2,self(siz[i]))%p;
        sum+=siz[i];add(head[i],1-temp);
    }printf("%lld\n",ans%p);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 24240kb

input:

3
1 3 2

output:

4

result:

ok "4"

Test #2:

score: 0
Accepted
time: 7ms
memory: 26476kb

input:

5
1 2 3 4 5

output:

1024

result:

ok "1024"

Test #3:

score: 0
Accepted
time: 5ms
memory: 26352kb

input:

6
4 2 1 5 6 3

output:

4096

result:

ok "4096"

Test #4:

score: -100
Time Limit Exceeded

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:


result: