Cod sursa(job #915705)

Utilizator AndreiTeodorAndrei R AndreiTeodor Data 15 martie 2013 11:18:34
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.39 kb
#include <fstream>
#include <vector>
using namespace std;

ifstream f("hasuri.in");
ofstream g("hashuri.out");

const int MOD = 1999999;

int num_queries;
vector<long> hashing[MOD+1];

int main()
{
    //Local variables
    int first, second, stop;
    vector<long>::iterator it;

    //Read the number of total queries
    f>>num_queries;

    //Read and solve every query
    while(num_queries--)
    {
        f>>first>>second;
        switch(first){
            case 1:
            {
                hashing[second%MOD].push_back(second);
                break;
            }
            case 2:
            {
                for(it=hashing[second%MOD].begin(); it!=hashing[second%MOD].end(); it++)
                    if(*it==second)
                    {
                        hashing[second%MOD].erase(it);
                        break;
                    }
                break;
            }
            case 3:
            {
                stop = 1;
                for(it=hashing[second%MOD].begin(); it!=hashing[second%MOD].end(); it++)
                    if(*it==second)
                    {
                        g<<1<<'\n';
                        stop = 0;
                        break;
                    }
                if(stop)
                    g<<0<<'\n';
                break;
            }
        }
    }


    return 0;
}