voidupdate(int x, int value, int cur = 0, int l = 1, int r = maxn){ if (x == l && l == r) { sub[cur] = value; return; } int mid = (l + r) >> 1u; if (x <= mid) { update(x, value, getLson(cur), l, mid); } else { update(x, value, getRson(cur), mid + 1, r); } up(cur); }
intquery(int x, int y, int cur = 0, int l = 1, int r = maxn){ if (x == l && y == r) return sub[cur]; int mid = (l + r) >> 1u; if (y <= mid) { returnquery(x, y, getLson(cur), l, mid); } elseif (x > mid) { returnquery(x, y, getRson(cur), mid + 1, r); } else { returnmin(query(x, mid, getLson(cur), l, mid), query(mid + 1, y, getRson(cur), mid + 1, r)); } } } segTree;
voidsolve(){ int q; cin >> q; segTree.init(); map<int, int> pool; // 当前集合中的数据 set<int> multi; // 用于处理重复数据 for (int i = 0; i < q; ++i) { int op, x; cin >> op >> x; switch (op) { case1: { auto iter = pool.find(x); if (iter != pool.end()) { iter->second++; if (iter->second == 2) multi.insert(x); } else { pool.insert({x, 1}); auto cur = pool.find(x); auto lower = cur, up = cur; up++; if (lower != pool.begin()) { lower--; segTree.update(lower->first, x - lower->first); } if (up != pool.end()) { segTree.update(x, up->first - x); } } } break; case2: { auto cur = pool.find(x); if (cur == pool.end()) break; cur->second--; if (cur->second == 1) { multi.erase(x); } elseif (cur->second == 0) { auto lower = cur, up = cur; up++;
segTree.update(x, INT_MAX); if (lower != pool.begin()) { lower--; if (up != pool.end()) segTree.update(lower->first, up->first - lower->first); else segTree.update(lower->first, INT_MAX); }
pool.erase(cur); } } break; case3: { auto iter = pool.upper_bound(x / 2); if (iter == pool.end()) { // 没有值比 x / 2 更大了,则不存在 a + b > x 了 cout << "No" << endl; break; }
auto lower = iter; if (lower != pool.begin()) { lower--; if (lower->first + iter->first <= x) { lower++; } }
auto mu = multi.lower_bound(iter->first); if (mu != multi.end()) { cout << "Yes" << endl; } else { int res = segTree.query(lower->first, maxn); if (res < x) cout << "Yes" << endl; else cout << "No" << endl; } } break; } } }