Cod sursa(job #2685346)

Utilizator SochuDarabaneanu Liviu Eugen Sochu Data 16 decembrie 2020 17:57:16
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.55 kb
#include <bits/stdc++.h>
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define FILES freopen("hashuri.in" , "r" , stdin) , freopen("hashuri.out" , "w" , stdout)

namespace FastRead
{
    char buff[5000];int lg = 0 , p = 0;
    char nc()
    {
        if(lg == p){lg = fread(buff , 1 , 5000 , stdin);p = 0;if(!lg) return EOF;}
        return buff[p++];
    }
    template<class T>void read(T&x)
    {
        T sgn = 1; char c;while(!isdigit(c = nc()))if(c == '-')sgn = -1;
        x = c - '0';while(isdigit(c = nc()))x = x * 10 + c - '0';x *= sgn;
    }
}

using namespace FastRead;
using namespace std;

const int M = 666013;

int type , x , n;
vector < int > H[M + 10];

inline vector < int > :: iterator find(int x)
{
    int h = x % M;
    vector < int > :: iterator i;

    for(i = H[h].begin() ; i != H[h].end() ; i++)
        if(*i == x)
            return i;

    return i;
}

inline void add(int x)
{
    vector < int > :: iterator p = find(x);

    if(p == H[x % M].end())
        H[x % M].push_back(x);
}

inline void erase(int x)
{
    vector < int > :: iterator p = find(x);

    if(p != H[x % M].end())
        H[x % M].erase(p);
}

signed main()
{
	#ifndef ONLINE_JUDGE
		FastIO , FILES;
	#endif

    int i;

    read(n);

    for(i = 1 ; i <= n ; i++)
    {
        read(type);
        read(x);

        if(type == 1)
            add(x);
        else if(type == 2)
            erase(x);
        else cout << (find(x) != H[x % M].end()) << '\n';
    }

    return 0;
}