Advertisement
GastonFontenla

Set

Jul 11th, 2020
1,180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     /**
  9.     Vienen Q consultas (1 <= Q <= 100.000)
  10.     La consulta de tipo A nos da un número
  11.     para agregar a una lista
  12.  
  13.     La consulta de tipo B nos da un número
  14.     y tenemos que decir si existe en la lista
  15.     que tenemos hasta el momento
  16.     **/
  17.  
  18.     /**
  19.     10
  20.     A 7
  21.     A 4
  22.     B 5
  23.     A 5
  24.     B 6
  25.     A 1000000
  26.     B 999
  27.     B 1000000
  28.     A 999
  29.     B 999
  30.     C 999
  31.  
  32.     NO
  33.     NO
  34.     NO
  35.     SI
  36.     SI
  37.     **/
  38.  
  39.     set <int> lista;
  40.     lista.insert(10);
  41.     lista.insert(10);
  42.     int cantidad = lista.count(10);
  43.  
  44.     int Q;
  45.     cin >> Q;
  46.  
  47.     for(int i=0; i<Q; i++)
  48.     {
  49.         char tipo;
  50.         int valor;
  51.         cin >> tipo >> valor;
  52.         if(tipo == 'A')
  53.         {
  54.             lista.insert(valor); ///log(lista.size())
  55.         }
  56.         else if(tipo == 'B')
  57.         {
  58.             if(lista.count(valor) == 0) ///log(lista.size())
  59.             {
  60.                 cout << "NO" << endl;
  61.             }
  62.             else
  63.             {
  64.                 cout << "SI" << endl;
  65.             }
  66.         }
  67.         else
  68.         {
  69.             if(lista.count(valor) == 0)
  70.             {
  71.                 cout << "No existe, no se puede borrar" << endl;
  72.             }
  73.             else
  74.             {
  75.                 lista.erase(lista.find(valor));
  76.             }
  77.         }
  78.     }
  79.  
  80.     ///Q*log(Q)
  81.  
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement