-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeforces-279C.cc
72 lines (57 loc) · 1.05 KB
/
Codeforces-279C.cc
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
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
void update(vector <int> &f, int idx, int val){
for(int i = idx; i < f.size(); i += i & -i){
f[i] += val;
}
}
int get(vector <int> &f, int idx){
int sum = 0;
for(int i = idx; i > 0; i -= i & -i){
sum += f[i];
}
return sum;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector <int> v(n);
for(int i = 0; i < n; i++){
cin >> v[i];
}
vector <int> u(n + 1, 0);
vector <int> d(n + 1, 0);
for(int i = 1; i < n; i++){
if(v[i] > v[i - 1]){
update(d, i + 1, 1);
}
if(v[i] < v[i - 1]){
update(u, i + 1, 1);
}
}
while(m--){
int l, r;
cin >> l >> r;
int left = l, right = r + 1;
while(left < right){
int mid = (left + right) / 2;
if(get(u, mid) - get(u, l) == 0){
left = mid;
} else {
right = mid;
}
if(left + 1 >= right) break;
}
if(get(d, r) - get(d, left) == 0){
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}