TLE70
#include
#include
int n,k,p,ans,sum[1000005],color[1000005],low[1000005],head[1000005],last[55];
int main(){
memset(last,-1,sizeof(last));
scanf("%d%d%d",&n,&k,&p);
for(int i=1;i<=n;i++){
scanf("%d%d",&color[i],&low[i]);
head[i]=last[color[i]];
last[color[i]]=i;
sum[i]=sum[i-1];
if(low[i]<=p)sum[i]++;
for(int j=head[i];j!=-1;j=head[j]){
if(sum[i]-sum[j-1])ans++;
// printf("ha%d %d\n",i,ans);
}
}
printf("%d\n",ans);
}
WA0
#include
#include
int n,k,p,emm,last,pre[55],sum[55],ans[55];
int main(){
last=-1;
scanf("%d%d%d",&n,&k,&p);
for(int i=1;i<=n;i++){
int x,y;
scanf("%d%d",&x,&y);
if(y<=p)last=i;
if(last>=pre[x])ans[x]+=sum[x];
emm+=ans[x];
sum[x]++;
pre[x]=i;
}
printf("%d\n",emm);
}
AC
#include
#include
int n,k,p,emm,last,pre[55],sum[55],ans[55];
int main(){
last=-1;
scanf("%d%d%d",&n,&k,&p);
for(int i=1;i<=n;i++){
int x,y;
scanf("%d%d",&x,&y);
if(y<=p)last=i;
if(last>=pre[x])ans[x]=sum[x];//bushi+=
emm+=ans[x];
sum[x]++;
pre[x]=i;
}
printf("%d\n",emm);
}