Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <stdio.h>
- using std::vector;
- using std::cin;
- using std::cout;
- using std::endl;
- typedef long long ll;
- int lower_bound(vector<int> * vec, int val)
- {
- if((*vec).size() == 1) return 0;
- int l = 0, r = (*vec).size() - 1;
- while(r - l > 1)
- {
- int mid = (l + r) / 2;
- if((*vec)[mid] < val) l = mid;
- else r = mid-1;
- }
- if((*vec)[l] < val && (*vec)[l+1] <= val) return l+1;
- return l;
- }
- int main()
- {
- //n - количество элементов в массиве(он упорядочен по неубыванию)
- //m - количество запросов
- int n
- cin >> n >> m;
- vector<int> v(n);
- for(int i = 0; i < n; i++) cin >> v[i];
- for(; m > 0; m--)
- {
- int val;
- cin >> val;
- int pos = lower_bound(&v, val);
- cout << v[pos] << endl;
- }
- return 0;
- }
- if ((*vec)[r] - val >= val - (*vec)[l])
- return l;
- return r;
Add Comment
Please, Sign In to add comment