Cod sursa(job #2784540)

Utilizator bibiancapitu2004Pitu Bianca bibiancapitu2004 Data 16 octombrie 2021 17:53:55
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.34 kb
#include <fstream>
#include <vector>
using namespace std;

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

const int MOD = 666013;
vector<int> h[MOD];

int main()
{
    int N;
    in >> N;

    int x, op;
    while(N--)
    {
        in >> op >> x;

        int r = x % MOD;
        if(op == 1)
        {
            bool gasit = false;
            for(vector<int>::iterator it = h[r].begin(); it != h[r].end();it ++)
            {
                if(*it == x)
                {
                    gasit = true;
                    break;
                }

            }
            if(!gasit)
                h[r].push_back(x);
        }
        else if(op == 2)
        {
            int poz = -1;
            for(int i = 0;i < (int)h[r].size();i ++)
            {
                if(h[r][i] == x)
                {
                    poz = i;
                    break;
                }

            }
            if(poz != -1)
            {
                swap(h[r][poz], h[r].back());
                h[r].pop_back();
            }
        }
        else{
            int gasit = 0;
            for(int i : h[r])
                if(i == x)
            {
                gasit = 1;
                break;
            }
            out << gasit << "\n";
        }
    }
    return 0;
}