Cod sursa(job #2646639)

Utilizator DormeoNoapte Buna Dormeo Data 1 septembrie 2020 16:55:10
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.05 kb
#include <bits/stdc++.h>
#define mod 666013

using namespace std;

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

vector < int > h[mod];

bool fnd(int x)
{
    int key = x % mod;
    for(auto v : h[key]) {
        if(v == x) return true;
    }
    return false;
}

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

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;
        }
    }
    if(it != h[key].end()) h[key].erase(it);
}

int main()
{
    int n;

    fin >> n;
    for(int i = 1; i <= n; ++i) {
        int type, x;

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