Cod sursa(job #2474370)

Utilizator BlkAlexAlex Negru BlkAlex Data 15 octombrie 2019 08:45:14
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.13 kb
#include <bits/stdc++.h>
#define MOD 100000007

using namespace std;

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

int n;
vector <int> Hash[MOD];

void op1(int x){
    int p = x % MOD;
    for (int i = 0; i < Hash[p].size(); i++){
        if (Hash[p][i] == x){
            return;
        }
    }
    Hash[p].push_back(x);
}

void op2 (int x){
    int p = x % MOD;
    for (int i = 0; i < Hash[p].size(); i++){
        if (Hash[p][i] == x){
            Hash[p].erase(Hash[p].begin() + i);
        }
    }
}

void op3 (int x){
    int p = x % MOD;
    for (int i = 0; i < Hash[p].size(); i++){
        if (Hash[p][i] == x){
            g << "1\n";
            return;
        }
    }
    g << "0\n";
    return;
}

void dostuff(){
    f >> n;
    for (;n--;){
        int op, val;
        f >> op >> val;
        if (op == 1){
            op1(val);
        } else {
            if (op == 2){
                op2(val);
            } else {
                op3(val);
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    dostuff();
    return 0;
}