Cod sursa(job #1423531)

Utilizator greenadexIulia Harasim greenadex Data 21 aprilie 2015 22:30:40
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

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

const int p = 666013;
vector <int> v[p];

int f(int nr){
    return nr % p;
}

int main()
{
    int N, op, x;
    fin >> N;
    for (; N; N--){
        fin >> op >> x;
        int im = f(x);
        if (op == 1){
            int ok = 1;
            for(auto it:v[im])
                if (it == x)
                    ok = 0;
            if (ok)
                v[im].push_back(x);

        }
        if (op == 2){
            for(auto &it:v[im])
                if (it == x){
                    swap(it,v[im].back());
                    v[im].pop_back();
                    break;
                }
        }
        if (op == 3){
            int ok = 0;
            for(auto it:v[im])
                if (it == x){
                    ok = 1;
                    break;
                }
            fout << (ok ? 1:0) << '\n';
        }
    }
    return 0;
}