Cod sursa(job #1795545)

Utilizator proflaurianPanaete Adrian proflaurian Data 2 noiembrie 2016 17:20:33
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <fstream>
#include <vector>

using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int p=100003;
int n,o,h,x;
vector<int> v[p];
int main()
{
    f>>n;
    for(;n;n--)
    {
        f>>o>>x;
        h=x%p;
        vector<int>::iterator it;
        for(it=v[h].begin();it!=v[h].end();it++)
            if(*it==x)
                break;
        if(o==1)
        {
            if(it==v[h].end())
                v[h].push_back(x);
        }
        else
            if(o==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;
}