Cod sursa(job #1957008)

Utilizator dumbraveanbDumbravean Bogdan dumbraveanb Data 7 aprilie 2017 11:20:46
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

#define Mod 666013
#define IT vector<int> :: iterator

int n, op, x;
vector<int> A[Mod];

IT Find(int x) {
    for(IT it = A[x % Mod].begin(); it != A[x % Mod].end(); ++it)
        if(*it == x)
            return it;
    return A[x % Mod].end();
}

void Ins(int x) {
    if(Find(x) == A[x % Mod].end())
        A[x % Mod].push_back(x);
}

void Del(int x) {
    IT y = Find(x);
    if(y != A[x % Mod].end())
        A[x % Mod].erase(y);

}
//
int main()
{
    fin >> n;
    for(int i = 1; i <= n; ++i) {
        fin >> op >> x;
        switch(op) {
            case 1 : Ins(x); break;
            case 2 : Del(x); break;
            case 3 : fout << (Find(x) != A[x % Mod].end()) << '\n'; break;
        }
    }
    return 0;
}