Cod sursa(job #539157)

Utilizator Magnuscont cu nume gresit sau fals Magnus Data 22 februarie 2011 15:54:37
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <stdio.h>
#include <vector>

using namespace std;

vector <int> h[666013];
int n,i,j,a,b,ok,x,y;

int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d",&n);
    for (i=1;i<=n;++i)
    {
        scanf("%d%d",&x,&y);
        if (x==1)
        {
            b=y%666013;a=h[b].size();ok=1;
            for (j=0;j<a;++j)
                if (h[b][j]==y) ok=0;
            if (ok) h[b].push_back(y);
        }
        else if (x==2)
        {
            ok=-1;b=y%666013;a=h[b].size();
            for (j=0;j<a;++j)
                if (h[b][j]==y) ok=j;
            if (ok!=-1)
            {
                h[b][ok]=h[b][a-1];
                h[b].pop_back();
            }
        }
        else
        {
            ok=0;b=y%666013;a=h[b].size();
            for (j=0;(j<a)&&(!ok);++j)
                if (h[b][j]==y)
                    ok=1;
            printf("%d\n",ok);
        }
    }
    return 0;
}