Cod sursa(job #2496476)

Utilizator Dragos1226Dragos Chileban Dragos1226 Data 20 noiembrie 2019 22:01:50
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include<fstream>
#include<vector>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int MOD = 666013;

vector <int> H[MOD];
int N;
int Find (int val) {
    int List = val % MOD;
    for (int i = 0; i < H[List].size(); i++)
        if(H[List][i] == val)
            return i;
    return -1;
}

void Insert (int val) {
    int List = val % MOD;
    if (Find(val) == -1)
        H[List].push_back(val);
}

void Delete (int val) {
    int List = val % MOD;
    int Pos = Find(val);
    if (Pos != -1)
        H[List][Pos] = H[List][H[List].size()-1],H[List].pop_back();

}

int main () {
    in >> N;
    while (N--) {
        int x, y;
        in >> x >> y;
        if (x == 1)
            Insert(y);
        if (x == 2)
            Delete(y);
        if (x == 3)
            out << (Find(y) != -1) << '\n';
    }
}