Cod sursa(job #1101626)

Utilizator muresan_bogdanMuresan Bogdan muresan_bogdan Data 8 februarie 2014 20:18:44
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.28 kb
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

const int MAXN = 666013;

vector<int> v[MAXN];
vector<int>::iterator aux;
int m, c, x;

vector<int>::iterator found(int y) {
    int pos = y % MAXN;
    vector<int>::iterator it;
    for(it = v[pos].begin(); it != v[pos].end(); it++) {
        if(*it == x) {
            return it;
        }
    }
    return v[pos].end();
}

void add(int y) {
    int pos = y % MAXN;
    v[pos].push_back(y);
}

void del(int y) {
    int pos = y % MAXN;
    vector<int>::iterator it = found(y);
    if(it != v[pos].end()) {
        v[pos].erase(it);
    }
}


int main() {
    fin >> m;
    while(m) {
        m--;
        fin >> c >> x;
        if(c == 1) {
            if(found(x) == v[x%MAXN].end()) {
                add(x);
            }
            continue;
        }
        if(c == 2) {
            del(x);
            continue;
        }
        if(c == 3) {
            if(found(x) == v[x%MAXN].end()) {
                fout << 0 << '\n';
            }
            else {
                fout << 1 << '\n';
            }
            continue;
        }
    }
    fin.close();
    fout.close();
    return 0;
}