#include using namespace std; const int inf = 1e9 + 5; const int pot = 1 << 20; multiset intervals[pot]; int tr[2*pot]; void act(int x) { tr[pot + x] = *intervals[x].begin(); for(int i = (pot + x) / 2; i >= 1; i /= 2) tr[i] = min(tr[2*i], tr[2*i+1]); } void rec(int id, int low, int high, int q_low, int q_high, int & ans) { if(high < q_low || q_high < low || tr[id] > q_high) return; if(id >= pot) { // leaf while(tr[id] <= q_high) { ++ans; intervals[id-pot].erase(intervals[id-pot].begin()); act(id-pot); } return; } rec(2 * id, low, (low + high) / 2, q_low, q_high, ans); rec(2 * id + 1, (low + high) / 2 + 1, high, q_low, q_high, ans); } int main() { for(int i = 0; i < 2 * pot; ++i) tr[i] = inf; int n, q; scanf("%d%d", &n, &q); for(int i = 1; i <= n; ++i) intervals[i].insert(inf); set unmarked; for(int i = 0; i <= n + 1; ++i) unmarked.insert(i); while(q--) { int type; scanf("%d", &type); if(type == 0) { int from, to; scanf("%d%d", &from, &to); if(*unmarked.lower_bound(from) > to) continue; intervals[from].insert(to); act(from); } else { int x; scanf("%d", &x); auto it = unmarked.find(x); assert(it != unmarked.end()); int high = *((++it)--) - 1; int low = *((--it)++) + 1; unmarked.erase(it); int ans = 0; // count and remove intervals completely in [low, high] rec(1, 0, pot - 1, low, high, ans); printf("%d\n", ans); fflush(stdout); } } }