Cod sursa(job #2893766)

Utilizator biancar28Radulescu Alexia-Bianca biancar28 Data 26 aprilie 2022 17:22:16
Problema Hashuri Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.65 kb
//#include <iostream>
//#include <fstream>
//#include <bits/stdc++.h>
//
//using namespace std;
//
//ifstream f("hashuri.in");
//ofstream g("hashuri.out");
//
//long n,x;
//int rez,op;
//
//int main() {
//
//    set<long>hash;
//    f>>n;
//    while(n!=0){
//        f>>op>>x;
//        auto poz = hash.find(x);
//        if(op==1 && *poz == hash.size()){
//            hash.insert(x);
//        }
//        if(op==2 && *poz != hash.size()){
//            hash.erase(poz);
//        }
//        if(op==3){
//            if(*poz != hash.size()){rez = 1;}
//            else rez = 0;
//            g<<rez<<endl;
//        }
//        n--;
//    }
//
//    return 0;
//}

#include <iostream>
#include <fstream>
#include <vector>
#include<iterator>

using namespace std;

ifstream f("hashuri.in");
ofstream g("hashuri.out");
#define P 50159
int n,x,op;
vector<int>List[P];

int find(int x){
    int mod;
    mod = x%P;
    for(int i=0;i<List[mod].size();i++)
    {
        if(List[mod][i]==x){
            return i;
        }
    }
    return -1;
}

void insert(int x){
    int mod,i;
    mod = x%P;
    if(find(x) == -1){
        List[mod].push_back(x);
    }
}

void erase(int x){
    int mod,i;
    mod = x%P;
    if(find(x)!=-1) {
        for (i = find(x)+1; i <=List[mod].size(); i++) {
            List[mod][i - 1] = List[mod][i];
        }
    }
}

int main(){

    f>>n;
    while(n!=0){

        f>>op>>x;
        if(op==1){
            insert(x);
        }
        else if(op==2){
            erase(x);
        }
        else if(op==3){
            int rez = find(x);
            if(rez == -1){g<<0<<endl;}
            else{g<<1<<endl;}
        }
        n--;
    }

    return 0;
}