Cod sursa(job #2341812)

Utilizator AlexAxeToporan Victor AlexAxe Data 12 februarie 2019 11:36:26
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");

const int MOD = 666013;
int N, Op, x, List;
vector <int> G[MOD + 2];

int Find(int x){
    List = x % MOD;
    for (int i = 0; i < (int)G[List].size(); ++i)
        if (G[List][i] == x)
            return i;
    return -1;
}

void Add(int x){
    if (Find(x) == -1)
        G[List].push_back(x);
}

void Delete(int x){
    int Pos = Find(x);
    if (Pos != -1)
        G[List].erase(G[List].begin() + Pos);
}

int main(){
    in >> N;
    for (int i = 1; i <= N; ++i){
        in >> Op >> x;
        if (Op == 1)
            Add(x);
        if (Op == 2)
            Delete(x);
        if (Op == 3)
            out << (Find(x) != -1) << '\n';
    }
    return 0;
}