#include #define lowbit(x) (x&(-x)) using namespace std; const int MAXN = 5e6 + 7; int c[MAXN]; int n; void ins(int x,int val) { while(x <= n){ c[x] += val; x += lowbit(x); } } int sum(int x) { int ans = 0; while(x) { ans += c[x]; x -= lowbit(x); } return ans; } /* 3 2 1 2 2 2 3 */ int main() { scanf("%d",&n); for(int i = 1;i <= n;i++) { int op,x; scanf("%d %d",&op,&x); if(op == 1) { int f = 0; if(sum(x) - sum(x - 1) != 1) f = 1; if(f) ins(x,1); } else if(op == 2) { int f = 0; if(sum(x) - sum(x - 1) != 1) f = 1; if(f) ins(x,1); if(sum(1) != 1) { if(f) ins(x,-1); puts("1"); continue; } int le = 0,ri = n + 1; int ans = n + 1; while(le <= ri) { int mid = le + ri >> 1; int s = sum(mid); if(s >= mid) le = mid + 1; else ri = mid - 1,ans = mid; } // if(sum(ans) == ans) for(int j = ans - 3;j <= ans + 3;j++) { if(j >= 0 && j < MAXN && sum(j) != j) { printf("%d\n",j); break; } } if(f) ins(x,-1); } } return 0; }