Cod sursa(job #2249449)

Utilizator manutrutaEmanuel Truta manutruta Data 29 septembrie 2018 21:19:21
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

ifstream f("hashuri.in");
ofstream g("hashuri.out");
#define cout g
//vector<int> v;

#define MOD 666013
vector<int> v[MOD];

int main()
{
    int t;
    f >> t;

    while (t)
    {
        t--;

        int op, x;
        f >> op >> x;

        int index = x%MOD;
        vector<int>::iterator it = find(v[index].begin(), v[index].end(), x);
        switch (op)
        {
            case 1:
            {
                if (it == v[index].end())
                {
                    v[index].push_back(x);
                }
            } break;

            case 2:
            {
                if (it != v[index].end())
                {
                    *it = v[index][v[index].size() - 1];
                    v[index].pop_back();
                }
            } break;

            case 3:
            {
                cout << (it != v[index].end()) << '\n';
            } break;
        }
    }

    return 0;
}