Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- int n, q, a;
- cin >> n;
- vector<int> arr(n);
- for(int i = 0; i < n; i++)
- cin >> arr[i];
- cin >> q;
- for(int i = 0; i < q; i++){
- cin >> a;
- if(arr.empty()){
- cout << 0 << endl;
- continue;
- }
- int lower = lower_bound(arr.begin(), arr.end(), a) - arr.begin();
- if(lower >= arr.size() || arr[lower] != a){
- cout << lower << endl;
- continue;
- }
- int upper = upper_bound(arr.begin(), arr.end(), a) - arr.begin() - 1;
- cout << lower << " " << upper << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment