Cod sursa(job #1740185)

Utilizator refugiatBoni Daniel Stefan refugiat Data 11 august 2016 08:39:03
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include <fstream>
#include <iostream>
#include <vector>
#define MOD 666013
using namespace std;
ifstream si("hashuri.in");
ofstream so("hashuri.out");
vector<int>l[MOD];
vector<int>::iterator findp(int val)
{
    int poz=val%MOD;
    vector<int>::iterator i;
    for(i=l[poz].begin();i!=l[poz].end();++i)
    {
        if(*i==val)
            return i;
    }
    return l[poz].end();
}
void update(int val)
{
    int poz=val%MOD;
    vector<int>::iterator i=findp(val);
    if(i==l[poz].end())
        l[poz].push_back(val);
}
void del(int val)
{
    int poz=val%MOD;
    vector<int>::iterator i=findp(val);
    if(i!=l[poz].end())
        l[poz].erase(i);
}
int main()
{
    int n;
    si>>n;
    int i,a,b;
    for(i=0;i<n;++i)
    {
        si>>a>>b;
        if(a==1)
        {
            update(b);
        }
        else
        {
            if(a==2)
            {
                del(b);
            }
            else
            {
                so<<(findp(b)!=l[b%MOD].end())<<'\n';
            }
        }
    }
    return 0;
}