Cod sursa(job #708029)

Utilizator freakingVlad Eu freaking Data 6 martie 2012 11:38:34
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.11 kb
#include <fstream>
#include <cstdio>
#include <vector>
#define nmax 599999
using namespace std;



vector <int> a[nmax];

int cauta(int x)
{
    int j;
    j=x%nmax;
    vector<int>::iterator it;
    for(it=a[j].begin();it!=a[j].end();++it)
    {
        if(*it==x)
        {
            return it-a[j].begin()+1;
        }
    }
    return 0;
}

void adaugare(int x)
{
    if(!cauta(x))
    {
        int j=x%nmax;
        vector<int>::iterator it;
        a[j].push_back(x);
    }
}

void sterge(int x)
{
    vector<int>::iterator it;
    int y;
    if(y=cauta(x))
    {
        int j=x%nmax;
        it=a[j].begin()+y-1;
        a[j].erase(it);
    }
}


int main()
{
    ofstream out("hashuri.out");
    int n,x,y,i;
    vector<int>::iterator it;
    ifstream in("hashuri.in");
    in>>n;
    for(i=1;i<=n;i++)
    {
        in>>x>>y;
        if(x==1)
        adaugare(y);
        else
        if(x==2)
        sterge(y);
        else
        if(x==3)
        if(cauta(y))
            out<<'1'<<"\n";
        else
            out<<'0'<<"\n";
    }
    return 0;
}