Cod sursa(job #2448861)

Utilizator HermioneMatei Hermina-Maria Hermione Data 17 august 2019 15:46:59
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <bits/stdc++.h>
using namespace std;
#define MOD 666013
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int> H[MOD];
int look(int x)
{
    int l=x%MOD;
    vector<int>::iterator it=find(H[l].begin(), H[l].end(), x);
    if(it!=H[l].end())
        return it-H[l].begin();
    else
        return -1;
}
void add(int x)
{
    if(look(x)==-1)
        H[x%MOD].push_back(x);
}
void del(int x)
{
    int l=x%MOD, p=look(x);
    if(p!=-1)
        H[l].erase(H[l].begin()+p);
}
int main()
{   int n, x, c;
    f>>n;
    for(int i=1;i<=n;i++)
    {
        f>>c>>x;
        if(c==1)
         add(x);
         else if(c==2)
         del(x);
         else if(look(x)!=-1) g<<1<<'\n';
         else g<<0<<'\n';


    }

    f.close();
    g.close();
    return 0;
}