数据结构我大概是废掉了……虽然考试时使用神奇的暴力过了80分,但是没有用dp和数据结构果然超时……线段树大法好
get到很高级的加速器register,虽然只能在for很大的数的时候用,但还是很流弊啊……
#include<cstdio>
#include<algorithm>
#define N 200002
using namespace std;
int n,k,p,a[N],b[N],color[51][N],ans=0;
struct Node
{
int minn;
Node *ls,*rs;
}pool[N*2+5],*tail=pool,*root;
Node *build(int l, int r)
{
Node *nd=++tail;
if(l==r)
nd->minn=b[l];
else
{
int mid=(l+r)>>1;
nd->ls=build(l,mid);
nd->rs=build(mid+1,r);
nd->minn=min(nd->ls->minn,nd->rs->minn);
}
return nd;
}
int query(Node *nd,int l,int r,int L,int R)
{
if(L<=l&&r<=R)
return nd->minn;
int mid=(l+r)>>1;
int _min=0x3FFFFF;
if(L<=mid)
_min=min(_min,query(nd->ls,l,mid,L,R));
if(R>mid)
_min=min(_min,query(nd->rs,mid+1,r,L,R));
return _min;
}
int main()
{
freopen( "hotel.in", "r", stdin );
freopen( "hotel.out", "w", stdout );
scanf("%d%d%d", &n, &k, &p);
for(register int i=1;i<=n;i++)
{
scanf("%d%d",&a[i],&b[i]);
color[a[i]][0]++;
color[a[i]][color[a[i]][0]]=i;
}
root=build(1,n);
for(register int i=0;i<k;i++)
{
int tot=color[i][0];
for(register int j=1;j<=tot;j++)
for(register int k=j+1;k<=tot;k++)
{
int u=color[i][j],v=color[i][k];
if(query(root,1,n,u,v)<=p)
{
ans+=color[i][0]-k+1;
break;
}
}
}
printf("%d",ans);
return 0;
}