Cod sursa(job #2494754)

Utilizator niculaandreiNicula Andrei Bogdan niculaandrei Data 18 noiembrie 2019 13:02:07
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>
#define MOD 100003

using namespace std;

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

int n, op, x;
vector < int > H[MOD + 5];

int Check(int x)
{
    int remain = x % MOD;
    for (int i = 0; i < H[remain].size(); i++)
        if (H[remain][i] == x)
            return i;
    return -1;
}

void Push(int x)
{
    if (Check(x) == -1)
        H[x % MOD].push_back(x);
}

void Pop(int x)
{
    int pos = Check(x);
    if (pos == -1)
        return;
    swap(H[x % MOD][pos], H[x % MOD][H[x % MOD].size() - 1]);
    H[x % MOD].resize(H[x % MOD].size() - 1);
}

int main()
{
    fin >> n;
    while (n--)
    {
        fin >> op >> x;
        if (op == 1)
            Push(x);
        else if (op == 2)
            Pop(x);
        else
            fout << (Check(x) != -1) << "\n";
    }
    return 0;
}