Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define endl "\n"
- using namespace std;
- int getLowerBound(vector<int> &v, int x) {
- int L=0, R = v.size(), mid;
- while(L < R) {
- mid = L + (R-L)/2;
- if(v[mid] < x) {
- L = mid + 1;
- } else {
- R = mid;
- }
- }
- return L;
- }
- /*
- int getUpperBound(vector<int> &v, int x) {
- return getLowerBound(v, x+1);
- }
- */
- int getUpperBound(vector<int> &v, int x) {
- int L=0, R = v.size(), mid;
- while(L < R) {
- mid = L + (R-L)/2;
- if(v[mid] <= x) {
- L = mid + 1;
- } else {
- R = mid;
- }
- }
- return L;
- }
- int main() {
- vector<int> v = {-5, 0, 0, 2, 3, 5, 7, 8, 8, 10};
- cout << getUpperBound(v, 11);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement