Cod sursa(job #2659564)

Utilizator DragosSDragos Sarbu DragosS Data 17 octombrie 2020 09:09:07
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <bits/stdc++.h>
#define M 700095
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector<int >v[M];
int x,y,t,h;
inline void Adauga()
{
    for(auto it: v[h])
        if(it==x)return;
    v[h].push_back(x);
}

void Sterge()
{
    for(vector<int>::iterator it=v[h].begin();it!=v[h].end();it++)
    {
        if(*it==x){ v[h].erase(it);return;}
    }
}
bool Query()
{
    for(auto it:v[h])
        if(it==x)return 1;
return 0;
}
int main()
{
    ios_base::sync_with_stdio(0);
    fin.tie(0);fout.tie(0);
    fin>>t;
    while(t--)
    {
        fin>>y>>x;
        h=x%M; ///functia hash
        if(y==1) Adauga();
        else if(y==2) Sterge();
        else fout<<Query()<<'\n';
    }
    fin.close();
    fout.close();
    return 0;
}