█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 1085

Problema 0x62 - Contar elementos mayores a X en un arreglo pequeño

  • Autor: svanegas
  • Fecha: 2020-10-09 23:00:27 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.005 s 1 KBi
#2
Correcto
0.005 s 5 KBi
#3
Correcto
0.006 s 1 KBi
#4
Correcto
0.005 s 1 KBi
#5
Correcto
0.005 s 1 KBi
#6
Correcto
0.005 s 1 KBi
#7
Correcto
0.006 s 1 KBi
#8
Correcto
0.005 s 1 KBi
#9
Correcto
0.006 s 1 KBi
#10
Correcto
0.005 s 1 KBi
Puntos totales: 100 / 100

Código

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int n, c, x;

int
main() {
  cin >> n;
  vector <ll> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  sort(v.begin(), v.end());
  cin >> c;
  while (c--) {
    cin >> x;
    vector<ll>::iterator low;
    // Binary search to find the place where the element x could be inserted
    // to keep non-decreasing order in the vector.
    low = upper_bound(v.begin(), v.end(), x);
    // Means that it is guaranteed that all elements before are less or equal
    // than x.
    cout << (v.end() - low) << endl;
  }
  return 0;
}