-
Notifications
You must be signed in to change notification settings - Fork 1
/
C.cpp
101 lines (82 loc) · 2.16 KB
/
C.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ara[100009], ics[100009], dcs[100009];
bool icon[100009], dcon[100009], is[100009], ds[100009];
int main()
{
bool iflag = 0, dflag = 0;
ll n, m;
cin >> n >> m;
for(ll i = 1; i <= n; i++) {
scanf("%lld", &ara[i]);
if(i != 1) {
if(ara[i] > ara[i - 1]) {
if(!iflag) {
ics[i] = 1;
iflag = 1;
dflag = 0;
is[i] = 1;
}
else
icon[i] = 1;
}
else if(ara[i] < ara[i - 1]) {
if(!dflag) {
//cout << ara[i - 1] << " " << ara[i] << endl;
dcs[i] = 1;
iflag = 0;
dflag = 1;
ds[i] = 1;
}
else
dcon[i] = 1;
}
}
}
for(ll i = 1; i <= n; i++) {
ics[i] += ics[i - 1];
dcs[i] += dcs[i - 1];
}
for(ll i = 1; i <= m; i++) {
ll l, r;
scanf("%lld %lld", &l, &r);
ll a = ics[r] - ics[l];
ll b = dcs[r] - dcs[l];
ll pos1 = -1, pos2 = -1;
//cout << dcs[r] << " " << dcs[l] << endl;
if(l != r) {
if(icon[l + 1] & !is[l + 1]) {
a++;
pos1 = l + 1;
}
if(dcon[l + 1] & !ds[l + 1]) {
b++;
pos2 = l + 1;
}
}
if(a > 1 || b > 1) {
printf("No\n");
continue;
}
if(a == 0 || b == 0) {
printf("Yes\n");
continue;
}
if(pos1 == -1)
pos1 = lower_bound(ics + l, ics + r + 1, ics[r]) - ics;
if(pos2 == -1)
pos2 = lower_bound(dcs + l, dcs + r + 1, dcs[r]) - dcs;
if(pos2 == l || pos1 == l) {
printf("Yes\n");
continue;
}
if(pos2 < pos1) {
printf("No\n");
//cout << pos2 << " " << pos1 << endl;
}
else
printf("Yes\n");
}
return 0;
}