Cod sursa(job #2038324)

Utilizator berindeiChesa Matei berindei Data 13 octombrie 2017 16:50:50
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include<bits/stdc++.h>
#define M 666013
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int h(int a){
    return a%M;
}
vector <int> ta[M-1];
vector <int>::iterator it;
int main(){
    int t, n, i, nr, a;
    in >> n;
    for (i=1; i<=n; i++){
        in >> t >> nr;
        a = h(nr);
        if (t == 1){
            if (find(ta[a].begin(), ta[a].end(), nr) != ta[a].end())
                ta[a].push_back(nr);
        }
        else if (t == 2){
            it = find(ta[a].begin(), ta[a].end(), nr);
            if (it!=ta[a].end()) ta[a].erase(it);
        }
        else{
            it = find(ta[a].begin(), ta[a].end(), nr);
            if (it!=ta[a].end())
                out << "1\n";
            else
                out << "0\n";
        }
    }
}