Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <set>
- #include <stack>
- #include <queue>
- #include <deque>
- using namespace std;
- #define TASK "set"
- vector < int > hash_map[1000000];
- int hash_f(int x) {
- return x % 1000000;
- }
- bool ex(int x) {
- int hx = hash_f(x);
- for (int i = 0; i < hash_map[hx].size(); i++) {
- if (hash_map[hx][i] == x) {
- return true;
- }
- }
- return false;
- }
- void ins(int x) {
- if (!ex(x)) {
- int hx = hash_f(x);
- hash_map[hx].push_back(x);
- }
- }
- void del(int x) {
- if (ex(x)) {
- int hx = hash_f(x);
- for (int i = 0; i < hash_map[hx].size(); i++) {
- if (hash_map[hx][i] == x) {
- hash_map[hx].erase(hash_map[hx].begin() + i);
- return;
- }
- }
- }
- }
- int main() {
- #ifdef _DEBUG
- freopen("debug.in", "r", stdin);
- freopen("debug.out", "w", stdout);
- #else
- freopen(TASK".in", "r", stdin);
- freopen(TASK".out", "w", stdout);
- #endif // _DEBUG
- string s;
- int x;
- while (cin >> s) {
- cin >> x;
- switch (s[0]) {
- case 'i': ins(x); break;
- case 'd': del(x); break;
- case 'e': cout << (ex(x) ? "true\n" : "false\n"); break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement