C

This is a solution by std::set.

if op=1op=1, we use .earse() to remove it.

if op=2op=2, we can use this code to find its precursors:

auto it = st.lower_bound(x);
--it

we should just print *it.

Pay attention, DON NOT USE std::endl, it may let your code TLE!

#include<bits/stdc++.h>
using namespace std;

int n, k;

int main() {
  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  cin >> n >> k;
  set<int> st;
  for (int i = 0; i <= n; ++i) st.insert(i);
  while (k--) {
    int op, x;
    cin >> op >> x;
    if (op == 1) {
      st.erase(x);
    }
    else {
      auto it = st.lower_bound(x);
      --it;
//       if (it == st.end()) cout << "0" << endl; else
      cout << *it << '\n';
    }
  }
}