Cod sursa(job #2897271)

Utilizator _andrei4567Stan Andrei _andrei4567 Data 3 mai 2022 10:47:36
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.14 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream cin ("hashuri.in");
ofstream cout ("hashuri.out");

const int N = 1e5;
const int MOD = 88807;

vector <int> v[N];

int n;

struct punct
{
    int cer, x;

} c;

vector<int>::iterator findus (int x)
{
    int cheie = x % MOD;
    for (vector <int>::iterator it = v[cheie].begin(); it != v[cheie].end(); ++it)
        if (*it == x)
            return it;
    return v[cheie].end();
}

void insertus (int x)
{
    int cheie = x % MOD;
    if (findus(x) == v[cheie].end())
        v[cheie].push_back(x);
}

void stergere (int x)
{
    int cheie = x % MOD;
    vector<int>::iterator it = findus(x);
    if (it != v[cheie].end())
        v[cheie].erase(it);
}


int main()
{
    for (cin >> n; n; --n)
    {
        cin >> c.cer >> c.x;
        switch(c.cer)
        {
        case 1:
            insertus(c.x);
            break;
        case 2:
            stergere(c.x);
            break;
        case 3:
            findus(c.x) == v[c.x % MOD].end() ? cout << "0\n" : cout << "1\n";
            break;
        }
    }

    return 0;
}