#include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; //每个位置只有0或者1两种情况 int a[5000005]; //原数组 int c[5000005]; //树状数组 int biaoji[5000005]; int n; //void init() //初始化a,c数组 //{ // memset(a, 0, sizeof(a)); // memset(c, 0, sizeof(c)); //} int lowbit(int x) { return x&(-x); } void updata(int i,int k) //在i位置加上k,并更新数组的数据 { while(i<=n) { c[i]+=k; i+=lowbit(i); } } int getsum(int i) //求前i项的和 { int ans=0; while(i>0) { ans+=c[i]; i-=lowbit(i); } return ans; } int getsum1(int i) //求前i项的和 { int ans=0; while(i>0) { ans+=c[i]; i-=lowbit(i); cout << ans << " bbbb" << endl; } return ans; } int main(){ // init(); cin >> n; for (int k=1;k<=n;k++){ int x,y; scanf("%d %d",&x,&y); if(x==1 && a[y] == 0){ updata(y, 1); a[y] = 1; } else if(x!=1){ int flag = 0; if(a[y] == 0){ flag = 1;a[y] = 1; updata(y, 1); } int l = 1 , r = n; int ans = 0; while(l <= r){ int mid = (l+r)/2; if(getsum(mid) == mid){ //满足条件 l = mid+1; ans = mid; } else r = mid-1; //不满足条件 } if(flag == 1){ a[y] = 0; updata(y, -1); } printf("%d\n",ans+1); } } return 0; }