Cod sursa(job #266197)

Utilizator vlad_DVlad Dumitriu vlad_D Data 25 februarie 2009 00:45:32
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> Hash[100000];
const int M = 99997;

int get_key(int X) {return X % M;}
void addHash(int X) {Hash[get_key(X)].push_back(X);}
void eraseHash(int X) {
       int key = get_key(X);

       for (int i = 0; i < Hash[key].size(); ++i) if (Hash[key][i] == X) {
           Hash[key][i] = Hash[key][ Hash[key].size() - 1];
           Hash[key].pop_back();
           return;
           }
       }
int isHash(int X) {
       int key = get_key(X);
       for (int i = 0; i < Hash[key].size(); ++i) if (Hash[key][i] == X) return 1;
       return 0;
       }
int main() {
    ifstream fin("hashuri.in");
    ofstream fout("hashuri.out");
    
    int n;
    fin >> n;
    while (n--) {
          int op, X;
          fin >> op >> X;
          if (op == 1) addHash(X);
          if (op == 2) eraseHash(X);
          if (op == 3) fout << isHash(X) << '\n';
          }
    return 0;
    }