Cod sursa(job #1993481)

Utilizator MaligMamaliga cu smantana Malig Data 23 iunie 2017 09:22:49
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.3 kb
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>

using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");

#define ll long long
#define pb push_back
#define ui unsigned int
const int inf = 1e9 + 5;
const int NMax = 1e5 + 5;
const int mod = 100005;

int M;
vector<int> v[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 elem : v[idx]) {
        if (elem == val) {
            return true;
        }
    }

    return false;
}

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

void rem(int val) {

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

        swap(v[idx][k],v[idx][v[idx].size()-1]);
        v[idx].pop_back();
        return;
    }
}