Cod sursa(job #1583557)

Utilizator cordun_cristinaCristina Maria Cordun cordun_cristina Data 29 ianuarie 2016 01:11:59
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");

const int rest = 666013;
int n;
vector <int> M[rest];

int Check(int x)
{
    int Line = x%rest;
    for(int i = 0; i < (int)M[Line].size(); i++)
        if(x == M[Line][i]) return i+1;
    return 0;
}

void Add(int x)
{
    int Line = x%rest;
    if(!Check(x)) M[Line].push_back(x);
}

void Delete(int x)
{
    int Line = x%rest;
    int i = Check(x) - 1;
    if(i != -1) M[Line].erase(M[Line].begin() + i);
}

int main()
{
    f>>n;
    while(n--)
    {
        int opt, x;
        f>>opt>>x;
        if(opt == 1) Add(x);
        if(opt == 2) Delete(x);
        if(opt == 3)
        {
            if(Check(x)) g<<1<<'\n';
            else g<<0<<'\n';
        }
    }
    return 0;
}