Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>/*rimi*/
- using namespace std;
- #define max 100005
- int ar[max];
- vector<int >tree(max*4);
- int k=1;
- pair<int, int> t[4*100];
- int n;
- int temp[1000001];
- long long match(int ar[],int left ,int mid, int right)
- {
- int count=0;
- int i,j,k,l,m,o,p;
- i = left;
- j = mid;
- k=left;
- while((i<mid) &&(j<=right))
- {
- if(ar[i]>ar[j])
- {
- temp[k++] = ar[j++];
- count += mid-i;
- }
- else
- {
- temp[k++] = ar[i++];
- }
- }
- while(i<mid)
- {
- temp[k++]=ar[i++];
- }
- while(j<=right)
- {
- temp[k++] = ar[j++];
- }
- for(i=left;i<=right;i++)
- {
- ar[i]=temp[i];
- }
- return count;
- }
- int partition(int ar[],int left, int right)
- {
- int count =0;
- if(left<right)
- {
- int mid = (left+right)/2;
- count+= partition(ar,left,mid);
- count+= partition(ar,mid+1,right);
- count+= match(ar,left,mid+1,right);
- }
- return count;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- long long int z,m,a,b,c,t,i,j,n,k,h,e,w,q,l,o,d;
- double dou;
- string s1,s2,str;
- map<string, int>ma;
- map<string, int>::iterator it;
- cin>>n;
- int ar[n];
- //int temp[n];
- for(i=0;i<n;i++)
- {
- cin>>ar[i];
- }
- cout<<partition(ar,0,n)<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement