DuskLight @ 2021-08-23 23:03:23
评测点
#include<iostream> //树状数组做法
#include<cstring>
#include<cstdio>
#include<algorithm>
#define f(a,b,c) for(int a=b;a<=c;a++)
#define lowbit(a) ((a)&(-a))
#define maxn 1000005
#define ll unsigned long long
using namespace std;
ll fread(){
ll x=0,s=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')s=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
x=x*10+(ch-'0');
ch=getchar();
}
return s==1?x:-x;
}
ll tree[maxn],a[maxn],b[maxn],n;
unsigned long long answer=0;
void add(ll index,ll x){
ll i=index;
for(;i<=n;i+=lowbit(i)){
tree[i]+=x;
}
}
bool com (ll u, ll v){
if(a[u]==a[v])return u>v;
return a[u]>a[v];
}
ll sum(ll x){
ll i=x,ans=0;
for(;i>0;i-=lowbit(i)){
ans+=tree[i];
}
return ans;
}
int main()
{
n=fread();
f(i,1,n){
a[i]=fread();
b[i]=i;
}
sort(b+1,b+n+1,com);
f(i,1,n){
add(b[i],1);
answer+=sum(b[i]-1);
}
printf("%d",answer);
return 0;
}
by iMya_nlgau @ 2021-08-23 23:04:55
@DuskLight 你 printf
用的 %d
by Yikara @ 2021-10-02 22:23:12
十年OI一场空,___