Evaluation PortalTest Instructions:
n the cows are barking at each other, each cow has a deaf-ear degree ai, position bi;
So that two cows can hear each other. Required Volume abs (BI-BJ) *max (AI, AJ)
The total volume at which all cows can hear each other
input
43 12 52) 64 3
Output
57
Ideas:
N-party violence is obviously, well written, but must be hung!
So we need to use data structures to optimize
Code
#include <stdio.h>#include<algorithm>#defineLowbit (x) x& (-X)#definell Long Longusing namespacestd;Const intmxn=21000;structNode {intId,pos,val;} A[MXN];intn,c[mxn][2];ll ans;BOOLCvpConstNode &p,ConstNode &q) {returnp.val<Q.val;}BOOLCopConstNode &p,ConstNode &q) {returnp.pos<Q.pos;}voidAddintXintKintd) { while(x<=N) {c[x][k]+=D; X+=lowbit (x); }}intQuerintXintk) {intRe=0; while(x) {re+=C[x][k]; X-=lowbit (x); } returnre;}intMain () {scanf ("%d",&N); for(intI=1; i<=n;++i) {scanf ("%d%d",&a[i].val,&A[i].pos); Add (i,1,1); } sort (A+1, A +1+N,cop); for(intI=1; i<=n;++i) {a[i].id=i; Add (i,0, A[i].pos); } sort (A+1, A +1+N,CVP); for(inti=n;i;--i) {Add (A[i].id,1,-1); Add (A[i].id,0,-A[i].pos); Ans+=(Long Long) a[i].val* (Quer (N,0) -2*quer (A[i].id,0) +A[i].pos* (Quer (a[i].id,1)*2-Quer (N,1)) ); } printf ("%lld", ans); return 0;}
Moofest POJ-1990