Cod sursa(job #3198918)

Utilizator gabiccGabriel Cocan gabicc Data 31 ianuarie 2024 00:31:23
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.89 kb
#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <set>

using namespace std;

#define NR 100003

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

//vector<set<int>> multime;

/*int main()
{
    int n, instr, val;
    fin >> n;
    multime.resize(NR);
    for(int i = 1; i <= n; ++i){
        fin >> instr >> val;
        switch(instr){
            case 1:{
                int hashh = val % NR;
                multime[hashh].insert(val);
                break;
            }

            case 2:{
                int hashh = val % NR;
                multime[hashh].erase(val);
                break;
            }

            case 3:{
                int hashh = val % NR;
                auto it = multime[hashh].find(val);
                if(it == multime[hashh].end())
                    fout << 0 << '\n';
                else fout << 1 << '\n';
                break;
            }
        }
    }
    return 0;
}
*/

int main(){
    int cont = 0;
    int n, instr, val;
    fin >> n;
    int* multime = new int[n];
    for(int i = 1; i <= n; ++i){
        fin >> instr >> val;
        //int hashh = val % NR;
        int poz = -1;
        for(int i = 0; i < cont; i++){
            if(multime[i] == val){
                poz = i;
            }
        }
        if(instr == 1){
            if(poz == -1){
                multime[cont] = val;
                cont++;
            }
        }
        else if(instr == 2){
            if(poz != -1){
                for(int i = poz + 1; i < cont; i++){
                    multime[i-1] = multime[i];
                }
                cont--;
            }
        }
        else if(instr == 3){
            if(poz != -1){
                fout << 1 << '\n';
            }
            else fout << 0 << '\n';
        }
    }
    return 0;
}