Cod sursa(job #803260)

Utilizator UMihneaUngureanu Mihnea UMihnea Data 27 octombrie 2012 12:00:14
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <cstdio>
#include <vector>
#define H 100009
using namespace std;
vector<int> V[H];
int m,c,x,h;
int main()
{

    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);

    vector<int>::iterator it;

    scanf("%d",&m);
    for(;m;m--)
    {
        scanf("%d%d",&c,&x);
        h=x%H;
        for(it=V[h].begin();it!=V[h].end();it++)
            if(*it==x)break;
        if(c==1)
        {
            if(it==V[h].end())
            V[h].push_back(x);
            continue;
        }
        if(c==2)
        {
            if(it!=V[h].end())
            {
                *it = V[h].back();
                V[h].pop_back();
            }
            continue;
        }
        if(it==V[h].end())printf("0\n");
        else printf("1\n");

    }
    return 0;
}