#include using namespace std; using ll = long long; using ull = unsigned long long; mt19937 mt(736); template class treap { struct node { using nodeptr = unique_ptr; const T x; const unsigned y; nodeptr l, r; explicit node(T x) : x(x), y(mt()), l(nullptr), r(nullptr) {} }; using nodeptr = typename node::nodeptr; static nodeptr make_node(T x) { return make_unique(x); } static nodeptr merge(nodeptr &&le, nodeptr &&ri) { if (le == nullptr) return std::move(ri); if (ri == nullptr) return std::move(le); if (le->y < ri->y) { auto rch = merge(std::move(le->r), std::move(ri)); le->r = std::move(rch); return move(le); } else { auto lch = merge(std::move(le), std::move(ri->l)); ri->l = std::move(lch); return move(ri); } } static pair split(nodeptr h, const T &x) { if (h == nullptr) return {nullptr, nullptr}; if (h->x < x) { auto [le, ri] = split(move(h->r), x); // structured binding, C++17 h->r = std::move(le); return {move(h), move(ri)}; } else { auto [le, ri] = split(move(h->l), x); h->l = move(ri); return {move(le), move(h)}; } } nodeptr root = nullptr; public: void insert(T x) { auto [le, ri] = split(std::move(root), x); root = merge(std::move(le), merge(make_node(x), std::move(ri))); } bool contains(T x) { auto [le, tmp] = split(std::move(root), x); auto [mi, ri] = split(move(tmp), x + 1); // <= x auto ans = (mi != nullptr); root = merge(move(le), merge(move(mi), move(ri))); return ans; } }; void solve(istream &cin = std::cin, ostream &cout = std::cout) { treap tr; int q; cin >> q; for (int i = 0; i < q; i++) { char type; int x; cin >> type >> x; if (type == '+') tr.insert(x); else if (type == '?') cout << tr.contains(x) << endl; else assert(false); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed; #ifdef LOCAL auto st = chrono::steady_clock::now(); ifstream fin("../input.txt"); do { solve(fin); cout << "===" << endl; string str; while (getline(fin, str) && str != string(max(1, (int) str.size()), '=')); } while (fin); #ifdef STRESS for (int cnt = 1;; cnt++) { stringstream ss, in1, out1, in2, out2; gen(ss); in1 << ss.str(); in2 << ss.str(); solve(in1, out1); stress(in2, out2); if (out1.str() != out2.str()) { cout << "fail: " << cnt << endl; cout << ss.str(); cout << "solve:" << endl; cout << out1.str(); cout << "stress:" << endl; cout << out2.str(); break; } else if (cnt % 100 == 0) cout << "ok: " << cnt << endl; } #endif cout << setprecision((int) floor(log10(chrono::steady_clock::duration::period::den))); cout << "clock: " << chrono::duration(chrono::steady_clock::now() - st).count() << endl; #else solve(); #endif return 0; }