Cod sursa(job #1049300)

Utilizator Maxim97Maxim Andrei Maxim97 Data 7 decembrie 2013 10:14:34
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 1.09 kb
#include <fstream>
#include <vector>
#define M 50000

using namespace std;

ifstream in("hashuri.in");
ofstream o("hashuri.out");

vector <int> R[50000];
int n,k;

int cauta(int x)
{
    int i,lg;
    k=x%M;
    lg=R[k].size();
    for(i=0;i<lg;i++)
    {
        if(R[k][i]==x)
            return i;
    }
    return -1;
}

int main()
{
    int x,op,poz;
    in>>n;
    while(n)
    {
        in>>op>>x;
        if(op==1)
        {
            if(cauta(x)==-1)
            {
              R[k].push_back(x);
            }
        }
        if(op==2)
        {
            poz=cauta(x);
            if(poz!=-1)
            {
                if(poz)
                {
                    R[k].erase(R[k].begin()+poz-1,R[k].begin()+poz);
                }
                else
                    R[k].erase(R[k].begin());
            }
        }
        if(op==3)
        {
            poz=cauta(x);
            if(poz==-1)
                o<<0;
            else
                o<<1;
            o<<'\n';
        }
        n--;
    }
    return 0;
}