Cod sursa(job #2896292)

Utilizator RaresParleaParlea Costin-Rares-Calin RaresParlea Data 29 aprilie 2022 21:52:56
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

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

vector <int> hash1[666018];

int main()
{   int i, k, n, j, x, op, r, gasit, poz,aux;
    k = 666013;
    fin>>n;
    for(i = 1; i <= n; i++){
        fin>>op>>x;
        gasit = 0;
        r = x % k;
        for(j = 0; j < hash1[r].size(); j++){
            if(hash1[r][j] == x){
                gasit = 1;
                poz = j;
                break;
            }
    }
    if(op == 1){
        if(gasit == 0)
            hash1[r].push_back(x);
    }
    else{
    if(op == 2){
        if(gasit == 1){
            swap(hash1[r][j],hash1[r].back());
            hash1[r].pop_back();
        }
    }
    else{
        if(gasit == 1)
            fout<<1<<'\n';
        else
            fout<<0<<'\n';

        }
    }
}
    return 0;
}