Cod sursa(job #2573709)

Utilizator BogdanRazvanBogdan Razvan BogdanRazvan Data 5 martie 2020 18:49:01
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <bits/stdc++.h>
#define mod 666013

using namespace std;

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

void usain_bolt()
{
    ios::sync_with_stdio(false);
    fin.tie(0);
}
vector < int > h[mod];

void add(int x)
{
    int key = x % mod;
    h[key].push_back(x);
}

bool findd(int x)
{
    int key = x % mod;
    for(size_t j = 0; j < h[key].size(); ++j) {
        if(h[key][j] == x) return true;
    }
    return false;
}

void eraser(int x)
{
    int key = x % mod;
    vector < int > ::iterator it;
    for(it = h[key].begin(); it != h[key].end(); ++it) {
        if(*it == x) break;
    }
    h[key].erase(it);
}

int main()
{
    usain_bolt();

    int q;

    fin >> q;
    for(; q; --q) {
        int type, x;

        fin >> type >> x;
        if(type == 1) {
            if(findd(x) == false) add(x);
        }
        else if(type == 2) {
            if(findd(x) == true) eraser(x);
        }
        else fout << findd(x) << "\n";
    }
    return 0;
}