[NOIP-2011-D1B]选择客栈-听说是二分或单调队列

哇t2又做不来,数据范围怎么这么大啊
暴力pass
先枚举一个右区间(p2旅客)然后向左边找有没有价格小于p的夜店,有的话在向左找左区间(p1旅客),

if(p2.color==p1.color),ans++。

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
struct s
{
	int a,b,c;
}s[2000005];
int main()
{
	int n,k,p;
	int ans=0;
	int tmp=0;
	scanf("%d%d%d",&n,&k,&p);
	for(int i=1;i<=n;i++)
	{
		int co,h;
		scanf("%d%d",&co,&h);
		if(h<=p) tmp=i;
		if(tmp>=s[co].a) s[co].c=s[co].b;
		s[co].a=i;
		ans+=s[co].c;
		s[co].b++;
	}
	printf("%d",ans);
}

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注