Cod sursa(job #2781160)

Utilizator Maftei_TudorMaftei Tudor Maftei_Tudor Data 8 octombrie 2021 17:52:04
Problema Hashuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.23 kb
#include <fstream>
#include <vector>

using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
#define MOD 666013
vector<vector<int>> m;

int n, tip, x;
int main()
{
    m.resize(MOD+2);
    fin>>n;
    for(int i=1; i<=n; i++)
    {
        fin>>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)
            {
                fout<<1<<'\n';
                ok=true;
                break;
            }
            if(ok==false)
                fout<<0<<'\n';
        }
    }
    return 0;
}