QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#720908 | #9477. Topological Sort | OneWan# | WA | 1ms | 5748kb | C++23 | 1022b | 2024-11-07 14:39:16 | 2024-11-07 14:39:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int long long
int a[200005];
const int mod=998244353;
int qmi(int a,int b){
int res=1;
while(b){
if(b&1)res=res*a%mod;
b/=2;
a=a*a%mod;
}
return res;
}
int lowbit(int x){
return x&(-x);
}
int tr[300005];
void add(int k,int val){
while(k<=200000){
tr[k]+=val;
k+=lowbit(k);
}
}
int get(int k){
int sum=0;
while(k){
sum+=tr[k];
k-=lowbit(k);
}
return sum;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
add(a[n],1);
int sum=0;
for(int i=n-1;i>=1;i--){
sum+=n-i;
sum-=get(a[i]);
if(a[i]>a[i+1]){
add(a[i+1],-1);
add(a[i],1);
}else{
add(a[i],1);
}
}
cout<<qmi(2,sum);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5680kb
input:
3 1 3 2
output:
4
result:
ok "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5748kb
input:
5 1 2 3 4 5
output:
1024
result:
ok "1024"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5620kb
input:
6 4 2 1 5 6 3
output:
4096
result:
ok "4096"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 5652kb
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:
79273677
result:
wrong answer 1st words differ - expected: '73428942', found: '79273677'