Cod sursa(job #1253431)

Utilizator lorundlorund lorund Data 1 noiembrie 2014 12:16:45
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <cstdio>
#include <vector>
#include <algorithm>
#define MOD 666013
using namespace std;

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

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

    scanf("%d", &t);
    for (;t--;){
        int op, x, mod;
        vector<int>::iterator pos;

        scanf("%d %d", &op, &x);
        mod = x%MOD;
        pos = find(v[mod].begin(), v[mod].end(), x);
        switch (op){
            case 1:
                if (pos==v[mod].end())
                    v[mod].push_back(x);
                break;
            case 2:
                if (pos!=v[mod].end()){
                    *pos = v[mod].back();
                    v[mod].pop_back();
                }
                break;
            case 3:
                printf("%d\n", pos!=v[mod].end() ? 1 : 0);
                break;
        }
    }
    return 0;
}