Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.004 s | 0 KBi |
#2 |
Correcto
|
0.004 s | 0 KBi |
#3 |
Correcto
|
0.004 s | 1 KBi |
#4 |
Correcto
|
0.004 s | 0 KBi |
#5 |
Correcto
|
0.004 s | 0 KBi |
#6 |
Correcto
|
0.004 s | 0 KBi |
#7 |
Correcto
|
0.006 s | 2 KBi |
#8 |
Correcto
|
0.009 s | 0 KBi |
#9 |
Correcto
|
0.005 s | 0 KBi |
#10 |
Correcto
|
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); int ans = nums.end() - upper_bound(nums.begin(), nums.end(), x); // cout << (ans ? n - (ans - 1) : 0) << endl; cout << ans << endl; } return 0; }