Cod sursa(job #2487640)

Utilizator DordeDorde Matei Dorde Data 5 noiembrie 2019 02:08:57
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <fstream>
#include <vector>
using namespace std;
int const NM = 1e6 + 1 , P = 666013;
ifstream f ("hashuri.in");
ofstream g ("hashuri.out");
vector <int> v [P + 1];
vector <int> :: iterator it;
void add (int x){
    v [x % P] . push_back (x);
}
void del (int x){
    for (int i = 0 ; i < v [x % P] . size () ; ++ i)
        if (v [x % P][i] == x){
            swap (v [x % P][i] , v [x % P][v [x % P] . size () - 1]);
            v [x % P] . pop_back ();
            return;
        }
}
bool find_ (int x){
    for (it = v [x % P] . begin () ; it != v [x % P] . end () ; ++ it)
        if (*it == x)
            return true;
    return false;
}
int main()
{
    int n;
    f >> n;
    while (n --){
        int op , x;
        f >> op >> x;
        if (op == 1)
            add (x);
        if (op == 2)
            del (x);
        if (op == 3)
            g << find_ (x) << '\n';
    }
    return 0;
}