Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- #define pii pair<int, int>
- #define f first
- #define s second
- vector<pii> num;
- int n, T;
- int main(){
- int x;
- scanf("%d", &n);
- num.assign(n, {0, 0});
- for(int i = 0; i < n; ++i){
- scanf("%d", &x);
- num[i] = {x, i};
- }
- sort(num.begin(), num.end());
- scanf("%d", &T);
- for(int i = 0; i < T; ++i){
- scanf("%d", &x);
- int l = 0;
- int r = n - 1;
- int ans = n;
- while(l <= r){
- int m = (l + r) / 2;
- if(num[m].f < x){ /// Go Right
- l = m + 1;
- } else { /// Go Left
- if(num[m].f == x){
- ans = min(ans, num[m].s);
- }
- r = m - 1;
- }
- }
- if(ans == n){
- cout << "Not found\n";
- } else {
- cout << ans + 1 << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement