1 条题解
-
1
我们考虑倒着将每一个人插入
发现如果插入的一个人是已经最下的人的2号位,那这个人就跑了
如果是1号位就顺次往后移
如果0号位直接坐下
递归求解
#include<iostream> #include<cstdio> using namespace std; bool Test_MLE_start; const int N=1e5+10; int T=1,n,m; int ans[N],ton[N],who[N]; struct node{ int x,y; }a[N]; inline int reads(){ char c=getchar(); int sum=0,f=1; while(!isdigit(c)){ if(c=='-') f=-1; c=getchar(); } while(isdigit(c)){ sum=(sum<<3)+(sum<<1)+(c^'0'); c=getchar(); } return sum*f; } inline void files(){ freopen("film.in","r",stdin); freopen("std.out","w",stdout); } inline void clr(){ // Don't forget! } int calc(int wo,int where,int ret){ if(!ton[where]){ ton[where]=ret; who[where]=wo; return 1; } else if(ton[where]==2){ ton[where]=ret; who[where]=wo; return 0; } else{ int ned=who[where]; if(ned>wo){ ton[where]=ret; who[where]=wo; return calc(ned,a[ned].y,2); } else return 0; } } bool Test_MLE_end; signed main(){ // printf("%lf Mb\n",(&Test_MLE_end-&Test_MLE_start-1)/1024.0/1024.0); // files(); // T=reads(); while(T--){ clr(); n=reads(),m=reads(); for(int i=1;i<=n;i++) a[i].x=reads(),a[i].y=reads(); for(int i=n;i>=1;i--){ ans[i]=ans[i+1]; if(!ton[a[i].x]) ton[a[i].x]=1,ans[i]++,who[a[i].x]=i; else ans[i]+=calc(i,a[i].x,1); } for(int i=1;i<=n;i++) printf("%d\n",ans[i]); } return 0; }
- 1
信息
- ID
- 234
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- (无)
- 递交数
- 76
- 已通过
- 17
- 上传者