Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.004 s | 0 KBi |
#2 |
Correcto
|
0.003 s | 10 KBi |
#3 |
Correcto
|
0.004 s | 4 KBi |
#4 |
Correcto
|
0.005 s | 0 KBi |
#5 |
Correcto
|
0.006 s | 0 KBi |
#6 |
Incorrecto
|
0.004 s | 0 KBi |
#7 |
Incorrecto
|
0.005 s | 0 KBi |
#8 |
Incorrecto
|
0.006 s | 1 KBi |
#9 |
Correcto
|
0.005 s | 13 KBi |
#10 |
Incorrecto
|
0.006 s | 0 KBi |
#include <bits/stdc++.h> using namespace std; #define vi vector<int> int binarySearch2(vi &arr, int x, int l, int r) { while (l <= r) { int mid = l + (r - l) / 2; if (arr[mid] > x && arr[mid-1] <= x) return mid; if (arr[mid] <= x) l = mid + 1; else r = mid - 1; } return -1; } int main() { int n, c, x; cin >> n; vi nums(n); for (auto &x : nums) cin >> x; sort(nums.begin(), nums.end()); cin >> c; while (c--) { cin >> x; int ans = binarySearch2(nums, x, 0, nums.size()-1); cout << (ans != -1 ? n - ans : 0) << endl; } return 0; }