Cod sursa(job #1775384)

Utilizator sergiunascaSergiu Nasca sergiunasca Data 10 octombrie 2016 12:27:29
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.34 kb
//
//  main.cpp
//  Hashuri
//
//  Created by Nasca Sergiu Alin on 10/10/16.
//  Copyright © 2016 Nasca Sergiu Alin. All rights reserved.
//

#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

vector<int> a[666014];

int find_hash(int x)
{
    int hash = x % 666013;
    for(int i = 0; i < a[hash].size(); ++i)
    {
        if(a[hash][i] == x)
        {
            return i;
        }
    }
    return -1;
}

void add_hash(int x)
{
    int hash = x % 666013;
    int pos = find_hash(x);
    if(pos == -1)
    {
        a[hash].push_back(x);
    }
}

void erase_hash(int x)
{
    int hash = x % 666013;
    int pos = find_hash(x);
    if(pos >= 0)
    {
        a[hash].erase(a[hash].begin() + pos);
    }
}

int main(int argc, const char * argv[])
{
    // 666013
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    
    int n, op, x;
    
    scanf("%d", &n);
    
    for(int i = 1; i <= n; ++i)
    {
        scanf("%d %d", &op, &x);
        
        if(op == 1)
        {
            add_hash(x);
        }
        else if(op == 2)
        {
            erase_hash(x);
        }
        else if(op == 3)
        {
            int pos = find_hash(x);
            if(pos == -1)
            {
                printf("0\n");
            }
            else printf("1\n");
        }
    }
    
    return 0;
}