Cod sursa(job #2555169)

Utilizator DooMeDCristian Alexutan DooMeD Data 23 februarie 2020 19:18:34
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.98 kb
#include<bits/stdc++.h>

using namespace std;

const int mod=666013;

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

int n,tip,elem,i,rest;
list<int> v[mod];
list<int>::iterator it;

void tip_1(int x)
{
    rest=x % mod;
    v[rest].push_back(x);
    //cout << "1 " << rest << " " << v[rest].size() << "\n";
}

void tip_2(int x)
{
    rest=x%mod;
    for(it=v[rest].begin(); it!=v[rest].end(); it++)
        if(*it==x) {
            v[rest].erase(it);
            break;
        }
}

bool tip_3(int x)
{
    rest=x%mod;
    //cout << "3 " << rest << " " << v[rest].size() << "\n";
    for(it=v[rest].begin(); it!=v[rest].end(); it++)
        if(*it==x) return true;
    return false;
}

int main()
{
    f >> n;
    for(i=1; i<=n; i++) {
        f >> tip >> elem;
        if(tip==1) {
            if(tip_3(elem)==false) tip_1(elem);
        }
        else if(tip==2) tip_2(elem);
        else g << tip_3(elem) << "\n";
    }
    return 0;
}