球助
查看原帖
球助
313716
EgLund楼主2020/11/21 18:54
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
#define L 0
#define R 1
struct point
{
	int x,
		type,
		num;
	friend
	bool operator<
	(point const& it,point const& other)
	{
		if(it.x!=other.x)return it.x<other.x;
		if(it.type!=other.type)return it.type<other.type;
		return it.num<other.num;
	}
}pts[40005];
struct command
{
	int l,
		r,
		i;
	friend
	bool operator<
	(command const& it,command const& other)
	{
		return it.i>other.i;
	}
}cmd[20005];//[l,r)
int n,ans;
bool flag[20005];
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>cmd[i].l>>cmd[i].r>>cmd[i].i;
		pts[2*i-1].x=cmd[i].l,pts[2*i-1].type=L,pts[2*i-1].num=i;
		pts[2*i].x=cmd[i].r+1,pts[2*i].type=R,pts[2*i].num=i;
	}
	sort(pts+1,pts+n+n+1);
	sort(cmd+1,cmd+n+1);
	for(int i=2;i<=2*n;i++)
	{
		if(pts[i].x>pts[i-1].x)
		{
			for(int j=n;j>=1;j--)
			{
				if((cmd[j].l<=pts[i-1].x)&&(pts[i].x<=cmd[j].r))
				{
					ans+=(pts[i].x-pts[i-1].x)*cmd[j].i;
					break;
				}
			}
		}
	}
	cout<<ans<<endl;
}
2020/11/21 18:54
加载中...