标签:lin first volume including and ota air ems amp
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 7077 | Accepted: 3181 |
Description
Input
Output
Sample Input
4 3 1 2 5 2 6 4 3
Sample Output
57
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <string> #include <map> #include <stack> #include <queue> #include <vector> #define inf 0x3f3f3f3f #define met(a,b) memset(a,b,sizeof a) #define pb push_back typedef long long ll; using namespace std; const int N = 2e4+10; const int M = 24005; const int mod=1e9+7; ll tree[2][N]; int n,m; struct man{ int x,v; bool operator< (const man &it)const{ return v<it.v; } }a[N]; void add(int k,int num){ while(k<=20000){ tree[1][k]+=num; tree[0][k]+=1; k+=k&(-k); } } ll Sum(int k,int d){ ll sum=0; while(k>0){ sum+=tree[d][k]; k-=k&(-k); } return sum; } int main() { scanf("%d",&n); int v,x; for(int i=1;i<=n;i++){ scanf("%d%d",&a[i].v,&a[i].x); } sort(a+1,a+1+n); ll ans=0; for(int i=1;i<=n;i++){ ll sump=Sum(a[i].x,0); ll sumx=Sum(a[i].x,1); ans+=a[i].v*(sump*a[i].x-sumx)+a[i].v*(Sum(20000,1)-sumx-(i-1-sump)*a[i].x); add(a[i].x,a[i].x); } printf("%lld\n",ans); return 0; }
标签:lin first volume including and ota air ems amp
原文地址:http://www.cnblogs.com/jianrenfang/p/6067861.html