1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
| #include <bits/stdc++.h>
using namespace std;
#define MAXN 8000000
const int maxn = 1e9;
struct SegTree { int tot; int sub[MAXN]; int lson[MAXN], rson[MAXN];
void init() { for (int i = 0; i < MAXN; ++i) sub[i] = INT_MAX; memset(lson, 0xff, sizeof(int) * MAXN); memset(rson, 0xff, sizeof(int) * MAXN); tot = 1; }
inline void up(int cur) { if (lson[cur] == -1 && rson[cur] == -1) sub[cur] = INT_MAX; else if (lson[cur] == -1) sub[cur] = sub[rson[cur]]; else if (rson[cur] == -1) sub[cur] = sub[lson[cur]]; else sub[cur] = min(sub[lson[cur]], sub[rson[cur]]); }
inline int getLson(int cur) { assert(tot < MAXN); if (lson[cur] == -1) lson[cur] = tot++; return lson[cur]; }
inline int getRson(int cur) { assert(tot < MAXN); if (rson[cur] == -1) rson[cur] = tot++; return rson[cur]; }
void update(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); }
int query(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) { return query(x, y, getLson(cur), l, mid); } else if (x > mid) { return query(x, y, getRson(cur), mid + 1, r); } else { return min(query(x, mid, getLson(cur), l, mid), query(mid + 1, y, getRson(cur), mid + 1, r)); } } } segTree;
void solve() { 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) { case 1: { 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; case 2: { auto cur = pool.find(x); if (cur == pool.end()) break; cur->second--; if (cur->second == 1) { multi.erase(x); } else if (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; case 3: { auto iter = pool.upper_bound(x / 2); if (iter == pool.end()) { 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; } } }
signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef ACM_LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); int test_index_for_debug = 1; char acm_local_for_debug; while (cin >> acm_local_for_debug) { if (acm_local_for_debug == '$') exit(0); cin.putback(acm_local_for_debug); if (test_index_for_debug > 20) { throw runtime_error("Check the stdin!!!"); } auto start_clock_for_debug = clock(); solve(); auto end_clock_for_debug = clock(); cout << "Test " << test_index_for_debug << " successful" << endl; cerr << "Test " << test_index_for_debug++ << " Run Time: " << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl; cout << "--------------------------------------------------" << endl; } #else solve(); #endif return 0; }
CPP
|