Cod sursa(job #2737867)

Utilizator RoberttoPopescu Paullo Robertto Karloss Robertto Data 5 aprilie 2021 11:31:36
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.93 kb
#include <iostream>
#include <fstream>
#include <vector>
#define rest 100007
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector <int> v[100017];

int operatie_tip_3(int y, int cheie)
{
    for(int i = 0; i < v[cheie].size(); i++)
    {
        if(v[cheie][i] == y)
            return 1;
    }
    return 0;
}

void operatie_tip_2(int y, int cheie)
{
    for(int i = 0; i < v[cheie].size(); i++)
    {
        if(v[cheie][i] == y)
        {
            v[cheie].erase(v[cheie].begin() + i);
            return;
        }
    }
}

void operatie_tip_1(int y, int cheie)
{
    for(int i = 0; i < v[cheie].size(); i++)
    {
        if(v[cheie][i] == y)
        {
            return;
        }
    }
    v[cheie].push_back(y);
}

int main()
{
    int x, y, n, cheie,ok;
    f >> n; // numarul de operatii
    for(int i = 0; i < n; i++)
    {
        f >> x >> y; // citim tipul operatiei, si numarul
        ok=0;
        cheie = y % rest;
        if(x == 1)
        {
            for(int j = 0; j < v[cheie].size(); j++)
            {
                if(v[cheie][j] == y)
                {
                    ok=1;
                    break;
                }
            }
            if(!ok)v[cheie].push_back(y);
        }
        else if(x == 2)
        {
            for(int j = 0; j < v[cheie].size(); j++)
            {
                if(v[cheie][j] == y)
                {
                    v[cheie].erase(v[cheie].begin() + j);
                    break;
                }
            }
        }
        else
        {
            for(int j = 0; j < v[cheie].size(); j++)
            {
                if(v[cheie][j] == y)
                {
                    g<<1<<'\n';
                    ok=1;
                    break;
                }
            }
            if(ok==0)
                g<<0<<'\n';
        }
    }
    return 0;
}