Cod sursa(job #869833)

Utilizator TheShadowsAlexandru Cristian TheShadows Data 2 februarie 2013 13:42:25
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.19 kb
#include<vector>
#include<cstdio>
using namespace std;
const int MOD = 666013;
vector <int> table[MOD];
void adauga(int x){
    int pos = x % MOD;
    vector <int>::iterator it, end=table[pos].end();
    for(it=table[pos].begin() ; it!=end ; ++it)
    {
        if(*it==x)
            return;
    }
    table[pos].push_back(x);
}
void elim(int x){
    int pos = x % MOD;
    vector <int>::iterator it, end=table[pos].end();
    for(it=table[pos].begin() ; it!=end ; ++it)
        if(*it==x)
        {
            table[pos].erase(it);
            return;
        }
}
bool exists(int x){
    int pos = x % MOD;
    vector <int>::iterator it, end=table[pos].end();
    for(it=table[pos].begin() ; it!=end ; ++it)
        if(*it==x)
            return true;
    return false;
}
int main(){
    FILE *in=fopen("hashuri.in","r"), *out=fopen("hashuri.out","w");
    int q, type, val;
    fscanf(in, "%d\n", &q);
    for(int i=1; i<=q; i++){
        fscanf(in, "%d %d\n", &type, &val);
        if(type==1)
            adauga(val);
        else if(type==2)
            elim(val);
        else if(type==3)
            fprintf(out, "%d\n", exists(val));
    }
    return 0;
}