Cod sursa(job #1333865)

Utilizator somuBanil Ardej somu Data 3 februarie 2015 17:38:17
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <iostream>
#include <fstream>
#include <vector>
#define mod 666613

using namespace std;

int n, op, value;
vector <int> H[mod];

int findPos(int x) {
    for (int i = 0 ; i < H[x%mod].size(); i++)
        if (H[x%mod][i] == x)
            return i;
    return -1;
}

void addValue(int x) {
    if (findPos(x) < 0)
        H[x%mod].push_back(x);
}

void eraseValue(int x) {
    int ind = findPos(x);
    if (ind < 0) return;
    swap(H[x%mod][ind], H[x%mod][H[x%mod].size()-1]);
    H[x%mod].pop_back();
}

int main() {

    ifstream fin("hashuri.in");
    ofstream fout("hashuri.out");
    
    fin >> n;
    
    for (int i = 1; i <= n; i++) {
        fin >> op >> value;

        if (op == 1)
            addValue(value);
        else if (op == 2)
            eraseValue(value);
        else
            findPos(value) < 0 ? fout << "0\n" : fout << "1\n";
    }
    
    fin.close();
    fout.close();
    
    return 0;
}