123789456ye @ 2019-05-29 22:30:52
代码如下
#include<bits/stdc++.h>
using namespace std;
#define N 500005
struct num
{
long long id,value;
bool operator < (const num &p) const
{
return value<p.value;
}
}nu[N];
int c[N],n;
long long ans;
int lowbit(int i)
{
return i&(-i);
}
int getsum(int x)
{
int sum=0;
for(int i=x; i; i-=lowbit(i))
sum+=c[i];
return sum;
}
void modify(int x,int delta)
{
for(int i=x; i<=n; i+=lowbit(i))
c[i]+=delta;
}
inline int read()
{
char ch=getchar();
int x=0,f=1;
while(ch<'0'||ch>'9')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("0out.txt","w",stdout);
n=read();
for(int i=1; i<=n; i++)
{
nu[i].value=read();
nu[i].id=i;
}
sort(nu+1,nu+1+n);
for(int i=1;i<=n;i++)
{
modify(nu[i].id,1);
ans+=i-getsum(nu[i].id);
}
printf("%lld\n",ans);
return 0;
}
by Mmmmidnight @ 2019-07-15 18:52:15
我也这样挂了,感谢
by _H1kar1 @ 2019-07-23 09:29:57
@归程 tqlOrzzzzzzzzz