Cod sursa(job #2196493)

Utilizator alexsandulescuSandulescu Alexandru alexsandulescu Data 19 aprilie 2018 16:05:25
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>
#define MOD 666013

using namespace std;

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

int N, tip, x;
vector<int> H[MOD];

std::vector<int>::iterator find(int x, int shelf) {
    auto it = H[shelf].begin();
    for( ; it != H[shelf].end(); it++)
        if(*it == x) return it;
    return it;
}
int main()
{
    f >> N;
    for(int i = 1; i <= N; i++) {
        f >> tip >> x;
        int shelf = x % MOD;
        auto poz = find(x, shelf);
        if(tip == 1 && poz == H[shelf].end()) H[shelf].push_back(x);
        else if(tip == 2 && poz != H[shelf].end()) H[shelf].erase(poz);
        else if(tip == 3) g << (poz != H[shelf].end()) << "\n";
    }
    return 0;
}