Cod sursa(job #2781164)

Utilizator Maftei_TudorMaftei Tudor Maftei_Tudor Data 8 octombrie 2021 17:59:54
Problema Hashuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.31 kb
#include <cstdio>
#include <vector>

using namespace std;
FILE *fin = fopen("hashuri.in","r");
FILE *fout = fopen("hashuri.out","w");
#define MOD 666013
vector<vector<int>> m;

int n, tip, x;
int main()
{

    m.resize(MOD+2);
    fscanf(fin, "%d\n", &n);
    for(int i=1; i<=n; i++)
    {
        fscanf(fin, "%d %d\n", &tip, &x);
        if(tip==1)
        {
            int cat=x/MOD;
            int rest=x%MOD;
            bool ok=false;
            for(int j=0; j<m[rest].size(); j++)
                if(m[rest][j]==cat) {ok=true; break;}
            if(ok==false) m[rest].push_back(cat);
        }
        else if(tip==2)
        {
            int cat=x/MOD;
            int rest=x%MOD;
            for(int j=0; j<m[rest].size(); j++)
                if(m[rest][j]==cat)
            {
                m.erase(m.begin()+j);
                break;
            }
        }
        else
        {
            int cat=x/MOD;
            int rest=x%MOD;
            bool ok=false;
            for(int j=0; j<m[rest].size(); j++)
                if(m[rest][j]==cat)
            {
                fprintf(fout, "%d\n", 1);
                ok=true;
                break;
            }
            if(ok==false)
                fprintf(fout, "%d\n", 0);
        }
    }
    return 0;
}