Cod sursa(job #1758608)

Utilizator MiricaMateiMirica Matei MiricaMatei Data 17 septembrie 2016 15:38:46
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <cstdio>
#include <vector>
using namespace std;
const int MOD = 666013;
vector<int>v[MOD];
vector<int>::iterator find(int x){
  int aux = x % MOD;
  vector<int>::iterator it;
  for (it = v[aux].begin(); it != v[aux].end(); it ++)
    if (*it == x)
      return it;
    return v[aux].end();
}
void insert(int x){
  int aux = x % MOD;
  if (find(x) == v[aux].end())
    v[aux].push_back(x);
}
void erase(int x){
  int aux = x % MOD;
  vector<int>::iterator it = find(x);
  if (it != v[aux].end())
    v[aux].erase(it);
}
int main(){
  freopen("hashuri.in", "r", stdin);
  freopen("hashuri.out", "w", stdout);
  int n, i, op, x;
  scanf("%d", &n);
  for (i = 1; i <= n; i ++){
    scanf("%d%d", &op, &x);
    if (op == 1)
      insert(x);
    else if (op == 2)
      erase(x);
    else
      printf("%d\n", find(x) != v[x % MOD].end());
  }
  return 0;
}