Cod sursa(job #2974641)

Utilizator MrPuzzleDespa Fabian Stefan MrPuzzle Data 4 februarie 2023 12:11:44
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.33 kb
#include<fstream>
#include<iostream>
#include<climits>
#include<algorithm>
#include<cstring>
#include<cmath>
#include <vector>
#include <queue>
#include <iomanip>

#define DIM 1000000
#define HASH 6000007

using namespace std;

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

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

int n,op,x;

vector <int> u[HASH+5];

int main(){

    f>>n;
    for(int i=1;i<=n;i++){
        f>>op>>x;
        if(op == 1){
            bool ok=1;
            for(auto it = u[x%HASH].begin();it!=u[x%HASH].end();it++){
                if(*it == x){
                    ok = 0;
                    break;
                }
            }
            if(ok){
                u[x%HASH].push_back(x);
            }
        }else if(op == 2){
            for(auto it = u[x%HASH].begin();it!=u[x%HASH].end();it++){
                if(*it == x){
                    u[x%HASH].erase(it);
                    break;
                }
            }
        }else if(op == 3){
            bool ok=0;
            for(auto it = u[x%HASH].begin();it!=u[x%HASH].end();it++){
                if(*it == x){
                    ok=1;
                    break;
                }
            }
            g<<ok<<'\n';
        }
    }
    f.close();
    g.close();
    return 0;
}