Cod sursa(job #1972245)

Utilizator GeorginskyGeorge Georginsky Data 22 aprilie 2017 16:23:41
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include <iostream>
#include <fstream>
#include <vector>
#define K 262583
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
vector<int> h[K];
bool _find_(int x){
    int key=x%K;
    for(int i=0; i<h[key].size(); i++){
        if(h[key][i]==x)return true;
    }
    return false;
}

void add(int x){
    if(!_find_(x))h[x%K].push_back(x);
}

void del(int x){
    int key=x%K;
    for(int i=0; i<h[key].size(); i++){
        if(h[key][i]==x){
            h[key].erase(h[key].begin()+i);
            return;
        }
    }
}

int main(){
    int n, x, y;
    in>>n;
    for(int i=1; i<=n; i++){
        in>>x>>y;
        if(x==1)add(y);
        else if(x==2)del(y);
        else out<<_find_(y)<<"\n";
    }
    return 0;
}