记录编号 359359 评测结果 AAAAAAAAAAAAAAA
题目名称 奔跑 最终得分 100
用户昵称 Gravatarkxxy 是否通过 通过
代码语言 C++ 运行时间 0.636 s
提交时间 2016-12-22 13:30:19 内存使用 1.46 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
const int maxn=50010;
int n,x,y,r;
struct T
{
	int timel,num;
}e[maxn<<1];
int cc[maxn<<1];
set<int>active;
set<int>seen;
inline int read()
{
	int x=0;
	char c=getchar();
	int f=1;
	while(c>'9'||c<'0')
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
inline bool cmp(int x,int y)
{
	return e[x].timel<e[y].timel;
}
inline void solve()
{
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		x=read(),y=read(),r=read();
		e[++cnt].timel=(-x-1)*r;
		e[cnt].num=y;
		e[++cnt].timel=(-x)*r;
		e[cnt].num=-y;
	}
	sort(cc+1,cc+cnt+1,cmp);
	int st=e[cc[1]].timel;
	for(int i=1;i<=cnt;i++)
	{
		int next=cc[i];
		if(e[next].timel==st)
		{
			if(e[next].num>=0)
				active.insert(e[next].num);
			else
				active.erase(-e[next].num);
		}
		else
		{
			int minn=0x7fffffff;
			set<int>::iterator k;
			for(k=active.begin();k!=active.end();k++)
			{
				int id=*k;
				minn=min(minn,id);
			}
			if(minn!=0x7fffffff)
				seen.insert(minn);
			st=e[next].timel;
			if(e[next].num>0)
				active.insert(e[next].num);
			else
				active.erase(-e[next].num);
		}
	}
	int ans=seen.size();
	printf("%d",ans);
}
int main()
{
	freopen("stampede.in","r",stdin);
	freopen("stampede.out","w",stdout);
	n=read();
	for(int i=1;i<=(n<<1);i++)
		cc[i]=i;
	solve();
	return 0;
}