Cod sursa(job #1519970)

Utilizator cristina_borzaCristina Borza cristina_borza Data 8 noiembrie 2015 10:38:13
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.21 kb
#include <fstream>
#include <vector>

#define PRIM 666013

using namespace std;

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

int op , ok , x , N , hx;
vector <int> h[PRIM + 5];

int main() {

    f >> N;

    for (int i = 0; i < N; ++i) {
        f >> op >> x;
        hx = x % PRIM;
        ok = 1;
        if (op == 1) {
            for (int j = 0 ; j < h[hx].size() ; ++j) {
                if (h[hx][j] == x) {
                    ok = 0;
                    break;
                }
            }
            if (ok) {
                h[hx].push_back(x);
            }
        }
        if (op == 2) {
            for (int j = 0 ; j < h[hx].size() ; ++j) {
                if (h[hx][j] == x) {
                    swap(h[hx][j] , h[hx][h[hx].size() - 1]);
                    h[hx].pop_back();
                }
            }
        }
        if (op == 3) {
            for (int j = 0 ; j < h[hx].size() ; ++j) {
                if (h[hx][j] == x) {
                    ok = 0;
                    g << 1 << '\n';
                    break;
                }
            }
            if (ok) {
                g << 0 << '\n';
            }
        }
    }
    return 0;
}