QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#785804 | #9663. Reverse Pairs Coloring | rotcar07 | WA | 1ms | 5736kb | C++23 | 653b | 2024-11-26 19:15:54 | 2024-11-26 19:16:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=3e5+5;
int n,t[maxn],a[maxn],pos[maxn];
inline void add(int x,int y){while(x<=n)t[x]+=y,x+=x&-x;}
inline int query(int x){int res=0;while(x)res+=t[x],x-=x&-x;return res;}
int main(){
std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i],pos[a[i]]=i;
long long ans=0;
for(int i=n;i>=1;i--){
if(pos[a[i]-1]<pos[a[i]]) ans-=query(a[i]);
add(a[i],1);add(max(a[i],a[i+1]),-1);
if(pos[a[i]]<pos[a[i]+1]) ans+=query(min(n,a[i]+1));
// cout<<i<<' '<<ans<<'\n';
}
cout<<ans<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5736kb
input:
9 5 9 1 8 2 6 4 7 3
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5612kb
input:
2 1 2
output:
0
result:
ok single line: '0'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5688kb
input:
2 2 1
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'