Cod sursa(job #1741446)

Utilizator ionanghelinaIonut Anghelina ionanghelina Data 13 august 2016 21:36:19
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.57 kb
#include<bits/stdc++.h>
#define VAL 666013
#define dim 1000005
using namespace std;
vector<int> v[VAL+5];
vector<int>::iterator it;
int n,op,x;
char buff[dim+5];
int poz=0;
void citeste(int &numar)
{
    numar=0;
    while(buff[poz]<'0' || buff[poz]>'9')
    {
        poz++;
        if (poz==dim)
        {
            fread(buff,1,dim,stdin);
            poz=0;
        }
    }
    while (buff[poz]>='0' && buff[poz]<='9')
    {
        numar=numar*10+buff[poz]-'0';
        poz++;
        if (poz==dim)
        {
            fread(buff,1,dim,stdin);
            poz=0;
        }
    }
}
void adauga(int x)
{
    int y=x%VAL;
    for(it=v[y].begin();it!=v[y].end();it++)
    {
        if (*it==x) return;
    }
    v[y].push_back(x);
}
void sterge(int x)
{
    int y=x%VAL;
    for(it=v[y].begin();it!=v[y].end();it++)
    {
        if (*it==x)
        {
            v[y].erase(it);
            return;
        }
    }
}
void interogare(int x)
{
    int y=x%VAL;
    for(it=v[y].begin();it!=v[y].end();it++)
    {
        if (*it==x)
        {
            printf("1\n");
            return ;
        }
    }
    printf("0\n");
}
int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    fread(buff,1,dim,stdin);
   // scanf("%d",&n);
   citeste(n);
    for(int i=1;i<=n;i++)
    {
        //scanf("%d%d",&op,&x);
        citeste(op);
        citeste(x);
        if (op==1) adauga(x);
            else
        if (op==2) sterge(x);
            else interogare(x);
    }
    return 0;
}