Cod sursa(job #2199864)

Utilizator bigmixerVictor Purice bigmixer Data 29 aprilie 2018 13:22:22
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#pragma GCC optimize("03")
#include <bits/stdc++.h>
#define mod 666013
#define asd vector <int> :: iterator

using namespace std;

ifstream in("hashuri.in");
ofstream out("hashuri.out");

int n,t,x;
vector <int> v[666123];

asd find(int x){
    int hsh=x%mod;
    for(asd it = v[hsh].begin(); it != v[hsh].end(); ++it)
        if(*it == x)
            return it;
    return v[hsh].end();
}

void bagain(int x){
    if(find(x) == v[x%mod].end())
        v[x%mod].push_back(x);
}

void scoate(int x){
    auto it = find(x);
    if(it!=v[x%mod].end())
        v[x%mod].erase(it);
}

int main(){
    ifstream fin("hashuri.in");
    ofstream fout("hashuri.out");
    fin >> n;
    for(int i=1;i<=n;i++){
        fin >> t >> x;
        if(t==1) bagain(x);
        else if(t==2) scoate(x);
        else fout << (find(x) != v[x % mod].end()) << '\n';
    }
}