标签:ica type clu class event div his tween cond
Input
Output
Sample Input
4 3 1 2 5 2 6 4 3
Sample Output
57
num数组维护的是比当前位置小的牛数量
dis数组维护的是比当前位置小的牛的距离和
cnt为总距离(i - num1) * a[i].x 为大于当前牛的距离
(cnt - len) - (i - num1) * a[i].x);
1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <cmath> 5 #include <algorithm> 6 #include <set> 7 #include <iostream> 8 #include <map> 9 #include <stack> 10 #include <string> 11 #include <vector> 12 #define pi acos(-1.0) 13 #define eps 1e-6 14 #define fi first 15 #define se second 16 #define lson l,m,rt<<1 17 #define rson m+1,r,rt<<1|1 18 #define bug printf("******\n") 19 #define mem(a,b) memset(a,b,sizeof(a)) 20 #define fuck(x) cout<<"["<<x<<"]"<<endl 21 #define f(a) a*a 22 #define sf(n) scanf("%d", &n) 23 #define sff(a,b) scanf("%d %d", &a, &b) 24 #define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c) 25 #define pf printf 26 #define FRE(i,a,b) for(i = a; i <= b; i++) 27 #define FREE(i,a,b) for(i = a; i >= b; i--) 28 #define FRL(i,a,b) for(i = a; i < b; i++) 29 #define FRLL(i,a,b) for(i = a; i > b; i--) 30 #define FIN freopen("DATA.txt","r",stdin) 31 #define lowbit(x) x&-x 32 #pragma comment (linker,"/STACK:102400000,102400000") 33 34 using namespace std; 35 typedef long long LL; 36 const int maxn = 2e5 + 10; 37 int num[maxn], dis[maxn], n; 38 struct node { 39 int v, x; 40 } a[maxn]; 41 int cmp(node A, node B) { 42 return A.v < B.v; 43 } 44 void update(int x, int key, int *d) { 45 while(x <= 41000) { 46 d[x] += key; 47 x += lowbit(x); 48 } 49 } 50 LL sum(int x, int *d) { 51 LL ret = 0; 52 while(x > 0) { 53 ret += d[x]; 54 x -= lowbit(x); 55 } 56 return ret; 57 } 58 int main() { 59 while(scanf("%d", &n) != EOF) { 60 mem(num, 0); 61 mem(dis, 0); 62 for (int i = 0 ; i < n ; i++) 63 scanf("%d%d", &a[i].v, &a[i].x); 64 sort(a, a + n, cmp); 65 LL ans = 0, cnt = 0; 66 for (int i = 0; i < n ; i++) { 67 LL num1 = sum(a[i].x, num); 68 LL len = sum(a[i].x, dis); 69 ans += a[i].v * (num1 * a[i].x - len + (cnt - len) - (i - num1) * a[i].x); 70 cnt += a[i].x; 71 update(a[i].x, a[i].x, dis); 72 update(a[i].x, 1, num); 73 } 74 printf("%lld\n", ans); 75 } 76 return 0; 77 }
标签:ica type clu class event div his tween cond
原文地址:https://www.cnblogs.com/qldabiaoge/p/9415735.html