Cod sursa(job #2571197)

Utilizator spartanul300Vasile Andrei spartanul300 Data 4 martie 2020 21:37:01
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.95 kb
#include <bits/stdc++.h>
#define mod 100003
using namespace std;

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

vector < pair <int,int > > v[100010];

void baga_in_hash(int val)
{
    int rest=val%mod;
    for(int i=0;i<v[rest].size();i++)
    {
        if(v[rest][i].first==val){v[rest][i].second=1;return;}
    }
    v[rest].push_back({val,1});
}

void sterge_din_hash(int val)
{
    int rest=val%mod;
    for(int i=0;i<v[rest].size();i++)
    {
        if(v[rest][i].first==val){v[rest][i].second=0;return;}
    }
}

int este_in_hash(int val)
{
    int rest=val%mod;
    for(int i=0;i<v[rest].size();i++)
    {
        if(v[rest][i].first==val)return(v[rest][i].second);
    }
    return 0;
}

int n,i,x,op;
int main()
{
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>op>>x;
        if(op==1)baga_in_hash(x);
        else if(op==2)sterge_din_hash(x);
        else g<<este_in_hash(x)<<'\n';
    }
    return 0;
}