标签:std str a.out clu priority 排列 map long ios
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <queue> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <stack> #include <map> using namespace std; const double clf =1e-8; //const double e= 2.718281828; const double PI = 3.141592653589793; const long int MAX=1e9; #define ll long long //const int mx=20000+1; //priority_queue<int > p; priority_queue<int ,vector<int> , greater<int> > pq; const int M = 1e5+5; typedef struct kid{ int h; int num; } kids; kids s[M],t[M]; void merger(int l,int r) { if(l+1<r) { int mid = l+(r-l)/2; int q=l,p=mid,i=l; merger(l,mid); merger(mid,r); while(q<mid||p<r) { if(p>=r||(q<mid&&s[q].h<=s[p].h)) { t[i]=s[q++]; t[i].num+=p-mid; } else { t[i]=s[p];p++; t[i].num+=mid-q; }i++; } for(int i=l;i<r;i++) s[i]=t[i]; } } int main() { freopen("data.in","r",stdin); //freopen("data.out","w",stdout); int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&s[i].h); s[i].num=0; } merger(0,n); ll sum=0; for(int i=0;i<n;i++) { sum+=((1+s[i].num)*s[i].num)/2; } printf("%lld\n",sum); return 0; }
标签:std str a.out clu priority 排列 map long ios
原文地址:http://www.cnblogs.com/acmtime/p/6444787.html