Cod sursa(job #2004069)

Utilizator MaligMamaliga cu smantana Malig Data 24 iulie 2017 20:28:49
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.29 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <cmath>
#include <vector>

#define ll long long
#define pb push_back
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");

const int NMax = 1e4 + 5;
const int inf = 1e9 + 5;
const int mod = 1e5 + 7;

int M;
vector<int> h[mod];

bool have(int);
void add(int);
void rem(int);

int main() {
    in>>M;
    while (M--) {
        int tip,x;
        in>>tip>>x;

        switch (tip) {
        case 1: {
            if (!have(x)) {
                add(x);
            }

            break;
        }
        case 2: {
            rem(x);

            break;
        }
        case 3: {
            out<<( (have(x)) ? 1 : 0)<<"\n";

            break;
        }
        }
    }

    in.close();out.close();
    return 0;
}

#define idx val % mod

bool have(int val) {
    for (int n : h[idx]) {
        if (n == val) {
            return 1;
        }
    }

    return 0;
}

void add(int val) {
    h[idx].pb(val);
}

void rem(int val) {
    for (int k=0;k < h[idx].size();++k) {
        if (h[idx][k] != val) {
            continue;
        }

        swap(h[idx][k],h[idx][h[idx].size()-1]);
        h[idx].pop_back();

        return;
    }
}