inlineintquery(){ if (S.size() <= 4) return0; int x = *--(--S.end()), y = *++S.begin(), z = Q.top(); return *--(--S.end()) - *++S.begin() - Q.top(); }
inlinevoidsolve_0(){ int x; scanf("%d", &x); if (S.size() == 1) return (void) S.erase(x); It = it = S.lower_bound(x); --it; ++It; if (*it) Q.erase(x - *it); if (*It != INF) Q.erase(*It - x); if (*it && *It != INF) Q.push(*It - *it); S.erase(x); printf("%d\n", query()); }
inlinevoidsolve_1(){ int x; scanf("%d", &x); if (S.empty()) return (void) S.insert(x); It = it = S.upper_bound(x); --it; if (*it) Q.push(x - *it); if (*It != INF) Q.push(*It - x); if (*it && *It != INF) Q.erase(*It - *it); S.insert(x); printf("%d\n", query()); }
intmain(){ cin >> n >> m; S.insert(0); S.insert(INF); for (int i = 1; i <= n; ++i) { int x; cin >> x; if (S.empty()) { S.insert(x); continue; } It = it = S.upper_bound(x); --it; if (*it) Q.push(x - *it); if (*It != INF) Q.push(*It - x); if (*it && *It != INF) Q.erase(*It - *it); S.insert(x); } printf("%d\n", query()); for (int i = 1; i <= m; ++i) { int opt; scanf("%d", &opt); if (opt == 1) solve_1(); else solve_0(); } return0; }