Cod sursa(job #1253428)

Utilizator lorundlorund lorund Data 1 noiembrie 2014 12:09:57
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.01 kb
#include <cstdio>
#include <vector>
#define MOD 666013
using namespace std;

int t;
vector<int> v[MOD];

int find(int x){
    int mod = x%MOD;

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

    return -1;
}

void add(int x){
    v[x%MOD].push_back(x);
}

void remove(int x){
    int mod=x%MOD, pos=find(x);

    if (pos!=-1){
        v[mod][pos] = v[mod].back();
        v[mod].pop_back();
    }
}

int main()
{
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);

    scanf("%d", &t);
    for (;t--;){
        int op, x;

        scanf("%d %d", &op, &x);
        switch (op){
            case 1:
                if (find(x)==-1){
                    add(x);
                }
                break;
            case 2:
                remove(x);
                break;
            case 3:
                printf("%d\n", find(x)!=-1 ? 1 : 0);
                break;
        }
    }
    return 0;
}