Cod sursa(job #3345842)

Utilizator serbanbBrindescu Serban serbanb Data 11 martie 2026 13:34:32
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.37 kb
#include <fstream>
#include <vector>
#include <queue>

using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

const int p = 1000007;

vector<vector<pair<int, bool>>> v;
int n;

void op1(int x)
{
    int r = x % p;
    for(int i = 0; i < v[r].size(); ++i){
        if(v[r][i].first == x){
            if(v[r][i].second){
                return;
            }
            else{
                v[r][i].second = true;
                return;
            }
        }
    }
    v[r].push_back(make_pair(x, true));
}

void op2(int x)
{
    int r = x % p;
    for(int i = 0; i < v[r].size(); ++i){
        if(v[r][i].first == x && v[r][i].second){
            v[r][i].second = false;
        }
    }
}

void op3(int x)
{
    int r  = x % p;
    for(int i = 0; i < v[r].size(); ++i){
        if(v[r][i].first == x && v[r][i].second){
            fout << 1 << '\n';
            return;
        }
    }
    fout << 0 << '\n';
}

int main()
{
    for(int i = 0; i < p; ++i){
        vector<pair<int, bool>> temp;
        v.push_back(temp);
    }
    fin >> n;
    for(int i = 0; i < n; ++i){
        int op, x;
        fin >> op >> x;
        if(op == 1){
            op1(x);
        }
        else if(op == 2){
            op2(x);
        }
        else{
            op3(x);
        }
    }
    return 0;
}