Cod sursa(job #2603134)

Utilizator As932Stanciu Andreea As932 Data 18 aprilie 2020 17:13:06
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.26 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

typedef long long ll;

const int MOD=700087;

vector <ll> v[MOD+5];

int n,op;
ll x;

void push()
{
    int rest=x%MOD;

    vector <ll>::iterator it;

    bool found=false;

    for(it=v[rest].begin();it<v[rest].end();it++)
        if(*it==x)
        {
            found=true;
            break;
        }

    if(!found)
        v[rest].push_back(x);
}

void pop()
{
    int rest=x%MOD;

    vector <ll>::iterator it;

    for(it=v[rest].begin();it<v[rest].end();it++)
        if(*it==x)
        {
            v[rest].erase(it);
            break;
        }
}

void check()
{
    int rest=x%MOD;

    vector <ll>::iterator it;

    bool found=false;

    for(it=v[rest].begin();it<v[rest].end();it++)
        if(*it==x)
        {
            found=true;
            break;
        }

    if(found)
        fout<<"1\n";
    else
        fout<<"0\n";
}

int main()
{
    fin>>n;

    for(int i=1;i<=n;i++)
    {
        fin>>op>>x;

        if(op==1)
            push();
        else if(op==2)
            pop();
        else
            check();
    }

    return 0;
}