-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Binary_Search.cpp
More file actions
61 lines (53 loc) · 1.32 KB
/
A_Binary_Search.cpp
File metadata and controls
61 lines (53 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fl float
#define dl double long
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define lo(x,start,end) for(int x=start;x<end;++x)
#define eif else if
// Not Solved
int main(){
int n,q;
ll a,b;
cin >> n >> q;
vector<pair<ll,ll>> v(n);
lo(i,0,n) cin >> v[i].F >> v[i].S;
while(q--){
string str;
cin >> str;
cin >> a >> b;
pair<ll,ll> pl = {a,b};
if(str=="lower"){
// cin >> a >> b;
auto lb = (lower_bound(v.begin(),v.end(),pl));
lb--;
if(lb!=v.end()){
cout << (lb-v.begin()) <<'\n';
}
else {
cout << -1 <<'\n';
}
}
// {a,b,c} -> {},{a},{b},{c},{}
eif(str=="upper"){
// cin >> a >> b;
auto ub = (upper_bound(v.begin(),v.end(),pl));
if(ub!=v.end()){
cout << (ub-v.begin()) <<'\n';
}
else {
cout << -1 <<'\n';
}
}
eif(str=="find"){
// cin >> a >> b;
if(binary_search(v.begin(),v.end(),pl)){
cout<<"found\n";
} else {cout<<"not found\n";}
}
}
}