Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- const int N = 2e5 + 228;
- const int M = 2e5;
- struct hashset {
- vector<int> a[N];
- int get_hash(int x) {
- x = abs(x);
- return x % M;
- }
- void insert(int x) {
- int hash = get_hash(x);
- if (che(x)) return;
- a[hash].push_back(x);
- }
- void del(int x) {
- if (!che(x)) return;
- int hash = get_hash(x);
- for (int i = 0; i < a[hash].size(); ++ i) {
- if (x == a[hash][i]) {
- swap(a[hash][i], a[hash][a[hash].size() - 1]);
- a[hash].pop_back();
- return;
- }
- }
- }
- bool che(int x){
- int hash = get_hash(x);
- for (int i : a[hash]) {
- if (i == x) return true;
- }
- return false;
- }
- };
- int32_t main() {
- ios_base::sync_with_stdio(0);
- freopen("set.in", "r", stdin);
- freopen("set.out", "w", stdout);
- hashset set;
- string s;
- while (cin >> s) {
- if ( s == "insert") {
- int q;
- cin >> q;
- set.insert(q);
- } else if (s == "delete") {
- int x;
- cin >> x;
- set.del(x);
- } else {
- int x;
- cin >> x;
- bool q = set.che(x);
- if (q)
- cout << "true" << endl;
- else
- cout << "false" << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement