Cod sursa(job #2107424)

Utilizator Teodor.mTeodor Marchitan Teodor.m Data 17 ianuarie 2018 10:15:49
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.3 kb
#include <bits/stdc++.h>

using namespace std;

const int p = 1009;

inline void debug()
{
	#ifndef ONLINE_JUDGE
	ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);
	#endif
}

vector < int > Hash[1008];

void type_1(int x) {
    int hash_value = x % p;

    bool found = 0;
    for(auto it: Hash[hash_value]) {
        if(x == it) {
            found = 1;
            break;
        }
    }

    if(found == 0)
        Hash[hash_value].push_back(x);
}

void type_2(int x) {
    int hash_value = x % p;

    for(int i = 0; i < Hash[hash_value].size(); ++i) {
        if(x == Hash[hash_value][i]) {
            Hash[hash_value].erase(Hash[hash_value].begin() + i);
            break;
        }
    }
}

bool type_3(int x) {
    int hash_value = x % p;

    for(auto it: Hash[hash_value]) {
        if(x == it)
            return 1;
    }

    return 0;
}

int main()
{
	debug();
	
    int m;
    cin >> m;

    for(int i = 1 ; i <= m; ++i) {
        int op, x;
        cin >> op >> x;

        if(op == 1) {
            type_1(x);
            continue;
        }

        if(op == 2) {
            type_2(x);
            continue;
        }

        if(op == 3) {
            cout << type_3(x) << '\n';
            continue;
        }

    }
	

	return 0;
}