Cod sursa(job #641704)

Utilizator bogdanrnRadu Bogdan Nicolae bogdanrn Data 29 noiembrie 2011 10:56:55
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.18 kb
#include <cstdlib>
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
vector <int> v[666013];
const int CONST=666013;
bool search(int x){
     int poz=x%CONST;
     vector <int> :: iterator it;
     for (it=v[poz].begin();it!=v[poz].end();it++){
         if (*it==x){
                    return 1;
                     break;
         }        
     }
    return 0;
}
void adauga(int x){
     if (search(x)==0){
          v[x%CONST].push_back(x);              
          }
}
void sterge(int x){
     int poz=x%CONST;
     vector <int> :: iterator it;
     for (it=v[poz].begin();it!=v[poz].end();it++){
         if (*it==x){
                     v[poz].erase(it);
                     break;
         }        
     }
}

int main(int argc, char *argv[])
{
    int i,n,x,op;
    in>>n;
    for (i=1;i<=n;i++){
        in>>op;
        in>>x;
        if (op==1){
                   adauga(x);
        } 
        else if (op==2)
        {
                sterge(x);
        } else {
                out<<search(x)<<"\n";
        }

    }
    
    
    
    return 0;
}