Cod sursa(job #1971200)

Utilizator usureluflorianUsurelu Florian-Robert usureluflorian Data 19 aprilie 2017 22:53:48
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <fstream>
#include <vector>
#define MOD 666013
using namespace std;
ifstream f ("hashuri.in");
ofstream g ("hashuri.out");
vector <int> v[666014];
int y,n,j,caz,nr,poz;
int usu(int x)
{
    return x%MOD;
}
int caut(int x)
{
    y=usu(x);
    for(int i=0;i<v[y].size();++i) if(v[y][i]==x) return i;
    return -1;
}
void bag(int x)
{
    y=usu(x);
    if(caut(x)==-1) v[y].push_back(x);
}
void scot(int t)
{
    int p=usu(t);
    if(caut(t)>=0)
    {
        poz=caut(t);
        v[p].erase(v[p].begin()+poz,v[p].begin()+poz+1);
    }
}
int main()
{
    f>>n;
    for(j=1;j<=n;++j)
    {
        f>>caz>>nr;
        if(caz==1) bag(nr);
        else if(caz==2) scot(nr);
        else
        {
            if(caut(nr)==-1) g<<0<<'\n';
            else g<<1<<'\n';
        }
    }
}