Cod sursa(job #2790367)

Utilizator andreiiorgulescuandrei iorgulescu andreiiorgulescu Data 28 octombrie 2021 20:47:32
Problema Hashuri Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <bits/stdc++.h>

using namespace std;

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

vector<int>a[666015];

const int mod = 666013;

int Find(int x)
{
    int value = x % mod;
    int n = a[value].size();
    for (int i = 0; i < n; i++)
        if (a[value][i] == x)
            return i;
    return -1;
}

void Add(int x)
{
    if(Find(x) == -1)
        a[x % mod].push_back(x);
}

void Erase(int x)
{
    int pos = Find(x);
    int value = x % mod;
    if (pos != -1)
        a[value].erase(a[value].begin() + pos);
}

int main()
{
    int n;
    in >> n;
    for (int i = 1; i <= n; i++)
    {
        int t,x;
        in >> t >> x;
        if (t == 1)
            Add(x);
        else if (t == 2)
            Erase(x);
        else
            out << (Find(x) != -1) << endl;
    }
    return 0;
}