Cod sursa(job #1483375)

Utilizator dorumusuroiFMI - Doru Musuroi dorumusuroi Data 9 septembrie 2015 09:44:51
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const char iname[] = "hashuri.in";
const char oname[] = "hashuri.out";
const int MOD = 1000033;
const int MAXN = 1000005;
vector<int> H[MOD];
int n;

int main()
{
    freopen(iname, "r", stdin);
    freopen(oname, "w", stdout);
    scanf("%d", &n);
    for(int i = 0; i < n; ++i){
        int c, val;
        scanf("%d %d", &c ,&val);
        int h = val % MOD;
        if(c == 1){
            if( find(H[h].begin(), H[h].end(),val) == H[h].end() )    H[h].push_back(val);
        }
        else if(c == 2){
            for(unsigned int i = 0; i < H[h].size(); ++i)
            if(H[h][i] == val){
                H[h][i] = H[h][H[h].size()-1];
                H[h].pop_back();
                break;
            }
        }
        else{
            if( find(H[h].begin(), H[h].end(), val) != H[h].end() ) printf("1\n");
            else printf("0\n");
        }
    }
    return 0;
}