Cod sursa(job #1953054)

Utilizator teodorgTeodor G teodorg Data 4 aprilie 2017 16:51:57
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int P = 100003;
vector<int> v[P];
int n,i,op,x;

int main()
{
    f>>n;
    for(i=1; i<=n; i++)
    {
        f>>op>>x;
        vector<int>::iterator it;
        int h=x%P;
        for(it=v[h].begin(); it!=v[h].end(); it++)
            if(*it==x)
                break;
        if(op==1)
        {
            if(it==v[h].end())
                v[h].push_back(x);
        }
        else if(op==2)
            {
                if(it!=v[h].end())
                {
                    *it=v[h].back();
                    v[h].pop_back();
                }
            }
        else if(it==v[h].end())
            g<<"0\n";
        else
            g<<"1\n";
    }
    return 0;
}