记录编号 60908 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 开会的鱼儿 最终得分 100
用户昵称 Gravatar了反取字名我擦 是否通过 通过
代码语言 C++ 运行时间 0.652 s
提交时间 2013-06-01 11:40:41 内存使用 6.42 MiB
显示代码纯文本
#include<iostream>
#include<fstream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<sstream>
#include<list>
#include<map>
#include<deque>
#include<queue>
#include<set>
#include<vector>
#define INF 0x7fffffff
#define mid (Stree[k].l+Stree[k].r)/2
#define midd (l+r)/2

using namespace std;
ifstream fi("fishb.in");
ofstream fo("fishb.out");

struct point
{
	long long v,x;
}fish[50000];
bool cmp(point p1,point p2)
{
	if(p1.v>p2.v)return true;
	else return false;
}
long long n,tra[100000];
typedef struct SegmentTree
{
	long long l,r;
	unsigned value,num;
};
SegmentTree Stree[200000];
void build(long long k,long long l,long long r)
{
	Stree[k].l=l,Stree[k].r=r;
	if(l==r)return;
	build(k<<1,l,midd);
	build(k<<1|1,midd+1,r);
}
void Add(long long k,long long x,long long value,long long num)
{
	Stree[k].value+=value,Stree[k].num+=num;
	if(Stree[k].l==x&&Stree[k].r==x)
		return;
	if(x<=mid)Add(k<<1,x,value,num);
	else Add(k<<1|1,x,value,num);
}
unsigned long long Ask(long long k,long long l,long long r)
{
	if(r<l)return 0;
	if(l==Stree[k].l&&r==Stree[k].r)
		return Stree[k].value;
	if(r<=mid)return Ask(k<<1,l,r);
	if(l>mid)return Ask(k<<1|1,l,r);
	return Ask(k<<1,l,mid)+Ask(k<<1|1,mid+1,r);
}
unsigned long long Asknum(long long k,long long l,long long r)
{
	if(r<l)return 0;
	if(l==Stree[k].l&&r==Stree[k].r)
		return Stree[k].num;
	if(r<=mid)return Asknum(k<<1,l,r);
	if(l>mid)return Asknum(k<<1|1,l,r);
	return Asknum(k<<1,l,mid)+Asknum(k<<1|1,mid+1,r);
}
void Initialize()
{
	fi>>n;
	build(1,1,20000);
	for(long long i=0;i<n;i++)
	{
		fi>>fish[i].v>>fish[i].x;
		Add(1,fish[i].x,fish[i].x,1);
	}
	sort(fish,fish+n,cmp);
}
unsigned long long ans=0;
void Processing()
{
	for(long long i=0;i<n;i++)
	{
		ans+=(Asknum(1,1,fish[i].x-1)*fish[i].x-Ask(1,1,fish[i].x-1))*fish[i].v;
		ans+=(Ask(1,fish[i].x+1,20000)-Asknum(1,fish[i].x+1,20000)*fish[i].x)*fish[i].v;
		Add(1,fish[i].x,-fish[i].x,-1);
	}
}
void Output()
{
	fo<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	
	Initialize();
	Processing();
	Output();
	
	fi.close();
	fo.close();
	return 0;
}