Cod sursa(job #2624100)

Utilizator StefansenNegulescu Stefan Stefansen Data 4 iunie 2020 15:07:00
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.22 kb
#include <bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include <unordered_set>
using namespace std;

const unsigned P = 665000;

ifstream f("muzica.in");
ofstream g("muzica.out");

vector<int> v[P];

    bool search(int x)
    {
        vector<int>::iterator itr;
        for(itr=v[x%P].begin(); itr!=v[x%P].end(); itr++)
            if(x==*itr)
                return true;
        return false;
    }

    void push(int x)
    {
        if(search(x) == false)
            v[x%P].push_back(x);
    }

    void pop(int x)
    {
        vector<int>::iterator itr;
        for(itr=v[x%P].begin(); itr!=v[x%P].end(); itr++)
            if(x==*itr)
            {
                v[x%P].erase(itr);
                break;
            }

    }

    void menu(int command, int x)
    {
        if(command == 1)
            push(x);
        else
        if(command == 2)
            pop(x);
        else
        if(command == 3)
            cout<<search(x)<<'\n';

    }



int main()

{
   int n;
   int c,x;

   f>>n;

   for(int i=0; i<n; i++)
   {
       f>>c>>x;
       menu(c,x);
   }

    f.close();
    g.close();
    return 0;


}