标签:sizeof i++ desc image tree produce ges struct sorted
Time Limit: 7000MS | Memory Limit: 65536K | |
Total Submissions: 71503 | Accepted: 26877 |
Description
Input
Output
Sample Input
5
9
1
0
5
4
3
1
2
3
0
Sample Output
6
0
Source
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n;long long ans; int num[500010],tree[500010]; struct nond{ int a,pos; }v[500010]; int lowbit(int t){ return t&(-t); } int cmp(nond x,nond y){ return x.a<y.a; } void change(int x,int opt){ for(int i=x;i<=n;i+=lowbit(i)) tree[i]+=opt; } int sum(int x){ int bns=0; for(int i=x;i>0;i-=lowbit(i)) bns+=tree[i]; return bns; } int main(){ while(cin>>n&&n!=0){ for(int i=1;i<=n;i++){ scanf("%d",&v[i].a); v[i].pos=i; } sort(v+1,v+1+n,cmp); for(int i=1;i<=n;i++) num[v[i].pos]=i; for(int i=1;i<=n;i++){ change(num[i],1); ans+=(i-sum(num[i])); } cout<<ans<<endl;ans=0; memset(tree,0,sizeof(tree)); } }
标签:sizeof i++ desc image tree produce ges struct sorted
原文地址:https://www.cnblogs.com/cangT-Tlan/p/9656664.html