Cod sursa(job #2974729)

Utilizator Vlad_NistorNIstor Vlad Vlad_Nistor Data 4 februarie 2023 15:04:05
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.27 kb
#include <bits/stdc++.h>
using namespace std;
#define MOD 999917

vector<int> has[MOD];


int main(void){
    ofstream cout("hashuri.out");
    ifstream cin("hashuri.in");
    int n;
    cin >> n;
    for(int i = 1;i<=n;i++){
        int c, x;
        cin >> c >> x;
        if(c == 1){
            int caut = x % MOD;
            bool adaug = 1;
            for(auto y: has[caut]){
                if(y == x){
                    adaug = 0;
                    break;
                }
            }
            if(adaug)has[caut].push_back(x);
        }else if(c == 2){
            int caut = x % MOD;
            vector<int>::iterator poz = has[caut].end()+1;
            for(vector<int>::iterator pz = has[caut].begin(); pz < has[caut].end();pz++){
                if(*pz == x){
                    poz = pz;
                    break;
                }
            }
            if(poz != has[caut].end()+1){
                has[caut].erase(poz);
            }
        }else{
            int caut = x % MOD;
            bool gasit =0 ;
            for(auto y: has[caut]){
                if(y == x){
                    gasit = 1;
                    break;
                }
            }
            cout << gasit << '\n';
        }
    }
}