Cod sursa(job #3140977)

Utilizator MihaiBunBunget Mihai MihaiBun Data 11 iulie 2023 15:40:55
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.18 kb
#include <fstream>
#include <vector>

using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n,i,t,x,ok,h,u,m;
const int N = 524287;
vector<int> a[N],b[N];


int main()
{
    f >> n;
    for(i = 1; i <= n; i++)
    {
        f >> t;
        if(t==1)
        {
            f >> x;
            m = x&N;
            u = -1;
            for(h = 0; h < a[m].size(); h++)
                if(a[m][h]==x) {u = h; h = n;}
            if(u==-1) {a[m].push_back(x); b[m].push_back(1);}
            else b[m][u] = 1;
        }
        else if(t==2)
        {
            f >> x;
            m = x&N;
            u = -1;
            for(h = 0; h < a[m].size(); h++)
                if(a[m][h]==x)
                {
                    u = h;
                    h = n;
                }
            if(u >= 0) b[m][u] = 0;
        }
        else
        {
            f >> x;
            ok = 0;
            m = x&N;
            u = 0;
            for(h = 0; h < a[m].size(); h++)
                if(a[m][h]==x) {ok = 1; u = h; h = n;}
            if((ok==1)and(b[m][u]==1)) g << "1\n";
            else g << "0\n";
        }
    }
    return 0;
}