output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int a[10005], b[10005];
int main() {
int n, m, i, j, mark, x, y, k;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= m; i++) {
int h = 0;
scanf("%d%d%d", &x, &y, &k);
if (k < x || k > y) {
printf("Yes\n");
continue;
}
mark = a[k];
for (j = x; j <= y; j++)
if (a[j] <= mark) h++;
if (h + x - 1 == k)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Generate a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10005], b[10005];
int main() {
int n, m, i, j, mark, x, y, k;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= m; i++) {
int h = 0;
scanf("%d%d%d", &x, &y, &k);
if (k < x || k > y) {
printf("Yes\n");
continue;
}
mark = a[k];
for (j = x; j <= y; j++)
if (a[j] <= mark) h++;
if (h + x - 1 == k)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int const maxn = (int)2e6 + 1, inf = (int)2e9 + 1;
map<char, int> pidr;
int n, m, ans, cur, sz, a[maxn], b, l[maxn], r[maxn], x[maxn];
bool used[maxn];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) {
cin >> l[i] >> r[i] >> x[i];
}
for (int i = 1; i <= m; i++) {
cur = 0;
for (int j = l[i]; j <= r[i]; j++)
if (a[j] < a[x[i]]) cur++;
if (l[i] + cur == x[i])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int const maxn = (int)2e6 + 1, inf = (int)2e9 + 1;
map<char, int> pidr;
int n, m, ans, cur, sz, a[maxn], b, l[maxn], r[maxn], x[maxn];
bool used[maxn];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) {
cin >> l[i] >> r[i] >> x[i];
}
for (int i = 1; i <= m; i++) {
cur = 0;
for (int j = l[i]; j <= r[i]; j++)
if (a[j] < a[x[i]]) cur++;
if (l[i] + cur == x[i])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e4 + 10;
const double eps = 1e-10;
const double PI = acos(-1.0);
const long long mod = 1e9 + 7;
int n, m;
int a[MAX];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
int l, r, p;
for (int i = 1; i <= m; ++i) {
scanf("%d%d%d", &l, &r, &p);
int k = 0;
for (int j = l; j <= r; ++j) {
if (a[j] < a[p]) k++;
if (k > p - l) break;
}
if (k != p - l) {
printf("No\n");
} else {
printf("Yes\n");
}
}
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e4 + 10;
const double eps = 1e-10;
const double PI = acos(-1.0);
const long long mod = 1e9 + 7;
int n, m;
int a[MAX];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
int l, r, p;
for (int i = 1; i <= m; ++i) {
scanf("%d%d%d", &l, &r, &p);
int k = 0;
for (int j = l; j <= r; ++j) {
if (a[j] < a[p]) k++;
if (k > p - l) break;
}
if (k != p - l) {
printf("No\n");
} else {
printf("Yes\n");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int Array[10005];
int main() {
int N, m, i, j, l, r, x, Count;
scanf("%d%d", &N, &m);
for (i = 1; i <= N; i++) scanf("%d", Array + i);
for (i = 1; i <= m; i++) {
Count = 0;
scanf("%d%d%d", &l, &r, &x);
for (j = l; j <= r; j++) {
if (Array[j] < Array[x]) Count++;
}
if (Count == x - l)
puts("Yes");
else
puts("No");
}
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int Array[10005];
int main() {
int N, m, i, j, l, r, x, Count;
scanf("%d%d", &N, &m);
for (i = 1; i <= N; i++) scanf("%d", Array + i);
for (i = 1; i <= m; i++) {
Count = 0;
scanf("%d%d%d", &l, &r, &x);
for (j = l; j <= r; j++) {
if (Array[j] < Array[x]) Count++;
}
if (Count == x - l)
puts("Yes");
else
puts("No");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int p[10010];
int n, m;
scanf("%d %d", &n, &m);
int l, r, x;
for (int i = 1; i <= n; i++) scanf("%d", p + i);
while (m--) {
scanf("%d %d %d", &l, &r, &x);
int a = 0;
for (int i = l; i <= r; i++)
if (p[i] < p[x]) a++;
if (a == x - l)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int p[10010];
int n, m;
scanf("%d %d", &n, &m);
int l, r, x;
for (int i = 1; i <= n; i++) scanf("%d", p + i);
while (m--) {
scanf("%d %d %d", &l, &r, &x);
int a = 0;
for (int i = l; i <= r; i++)
if (p[i] < p[x]) a++;
if (a == x - l)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d%d", &n, &m);
;
int arr[n + 10];
for (int i = int(1) - (1 > n + 1); i != (n + 1) - (1 > n + 1);
i += 1 - 2 * (1 > n + 1)) {
scanf("%d", &arr[i]);
}
while (m--) {
int x, y, z;
scanf("%d%d", &x, &y);
;
scanf("%d", &z);
if (z < x || z > y)
puts("Yes");
else {
int cnt = 0;
for (int i = z; i > x; i--) {
if (arr[z] < arr[i - 1]) {
cnt++;
}
}
int knt = 0;
for (int i = z; i < y; i++) {
if (arr[z] > arr[i + 1]) {
knt++;
}
}
if (cnt != knt) {
puts("No");
continue;
}
puts("Yes");
}
}
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d%d", &n, &m);
;
int arr[n + 10];
for (int i = int(1) - (1 > n + 1); i != (n + 1) - (1 > n + 1);
i += 1 - 2 * (1 > n + 1)) {
scanf("%d", &arr[i]);
}
while (m--) {
int x, y, z;
scanf("%d%d", &x, &y);
;
scanf("%d", &z);
if (z < x || z > y)
puts("Yes");
else {
int cnt = 0;
for (int i = z; i > x; i--) {
if (arr[z] < arr[i - 1]) {
cnt++;
}
}
int knt = 0;
for (int i = z; i < y; i++) {
if (arr[z] > arr[i + 1]) {
knt++;
}
}
if (cnt != knt) {
puts("No");
continue;
}
puts("Yes");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
long n, m;
scanf("%ld %ld", &n, &m);
std::vector<long> a(n);
for (long p = 0; p < n; p++) {
scanf("%ld", &a[p]);
}
while (m--) {
long l, r, x;
scanf("%ld %ld %ld", &l, &r, &x);
--l;
--r;
--x;
long count(0);
for (long p = l; p <= r; p++) {
count += (a[p] < a[x]);
}
puts((count == x - l) ? "Yes" : "No");
}
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
int main() {
long n, m;
scanf("%ld %ld", &n, &m);
std::vector<long> a(n);
for (long p = 0; p < n; p++) {
scanf("%ld", &a[p]);
}
while (m--) {
long l, r, x;
scanf("%ld %ld %ld", &l, &r, &x);
--l;
--r;
--x;
long count(0);
for (long p = l; p <= r; p++) {
count += (a[p] < a[x]);
}
puts((count == x - l) ? "Yes" : "No");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int a[N];
int dp[N];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
while (m--) {
int L, R, x;
scanf("%d %d %d", &L, &R, &x);
int val = a[x];
int pos = (x - L) + 1;
int cnt = 0;
for (int i = L; i <= R; i++) {
if (a[i] <= val) cnt++;
}
if (pos == cnt) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int a[N];
int dp[N];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
while (m--) {
int L, R, x;
scanf("%d %d %d", &L, &R, &x);
int val = a[x];
int pos = (x - L) + 1;
int cnt = 0;
for (int i = L; i <= R; i++) {
if (a[i] <= val) cnt++;
}
if (pos == cnt) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int a[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
int l, r, p;
cin >> l >> r >> p;
int count = 0;
int num = a[p];
for (int i = l; i <= r; i++) {
if (a[p] > a[i]) count++;
}
if (count + l == p)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
| ### Prompt
Create a solution in CPP for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int a[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
int l, r, p;
cin >> l >> r >> p;
int count = 0;
int num = a[p];
for (int i = l; i <= r; i++) {
if (a[p] > a[i]) count++;
}
if (count + l == p)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <typename X>
inline X sqr(const X& a) {
return a * a;
}
int nxt() {
int x;
cin >> x;
return x;
}
int main() {
int n = nxt(), m = nxt();
vector<int> a(n);
generate(a.begin(), a.end(), nxt);
while (m--) {
int l = nxt() - 1, r = nxt(), x = nxt() - 1;
int cnt = 0;
for (int i = int(l); i < int(r); ++i) {
cnt += a[i] < a[x];
}
cout << (x == l + cnt ? "Yes" : "No") << '\n';
}
return 0;
}
| ### Prompt
Generate a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename X>
inline X sqr(const X& a) {
return a * a;
}
int nxt() {
int x;
cin >> x;
return x;
}
int main() {
int n = nxt(), m = nxt();
vector<int> a(n);
generate(a.begin(), a.end(), nxt);
while (m--) {
int l = nxt() - 1, r = nxt(), x = nxt() - 1;
int cnt = 0;
for (int i = int(l); i < int(r); ++i) {
cnt += a[i] < a[x];
}
cout << (x == l + cnt ? "Yes" : "No") << '\n';
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int l, r, x;
int p[10005];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> p[i];
for (int i = 1; i <= m; i++) {
cin >> l >> r >> x;
int k = 0;
for (int i = l; i <= r; i++)
if (p[i] < p[x]) k++;
if (p[l + k] == p[x])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
int l, r, x;
int p[10005];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> p[i];
for (int i = 1; i <= m; i++) {
cin >> l >> r >> x;
int k = 0;
for (int i = l; i <= r; i++)
if (p[i] < p[x]) k++;
if (p[l + k] == p[x])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
while (m--) {
int l, r, cnt = 0;
scanf("%d %d %d", &l, &r, &x);
l--;
r--;
x--;
for (int i = l; i <= r; i++) {
if (a[i] < a[x]) cnt++;
}
if (cnt == x - l)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
while (m--) {
int l, r, cnt = 0;
scanf("%d %d %d", &l, &r, &x);
l--;
r--;
x--;
for (int i = l; i <= r; i++) {
if (a[i] < a[x]) cnt++;
}
if (cnt == x - l)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
inline int input() {
int n;
cin >> n;
return n;
}
long long pw(long long a, long long b) {
return (!b ? 1 : (b & 1 ? a * pw(a * a, b / 2) : pw(a * a, b / 2)));
}
const long long MAXN = 1e5;
long long n, m, l, r, x, ind, p[MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
cin >> n >> m;
for (long long i = 1; i <= n; i++) cin >> p[i];
while (m--) {
cin >> l >> r >> x;
ind = l;
for (long long i = l; i <= r; i++)
if (p[i] < p[x]) ind++;
cout << (ind == x ? "Yes" : "No") << endl;
}
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline int input() {
int n;
cin >> n;
return n;
}
long long pw(long long a, long long b) {
return (!b ? 1 : (b & 1 ? a * pw(a * a, b / 2) : pw(a * a, b / 2)));
}
const long long MAXN = 1e5;
long long n, m, l, r, x, ind, p[MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
cin >> n >> m;
for (long long i = 1; i <= n; i++) cin >> p[i];
while (m--) {
cin >> l >> r >> x;
ind = l;
for (long long i = l; i <= r; i++)
if (p[i] < p[x]) ind++;
cout << (ind == x ? "Yes" : "No") << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
while (*sdbg != ',') cerr << *sdbg++;
cerr << "=" << h << ",";
_dbg(sdbg + 1, a...);
}
int test;
int n, m;
int t[500007];
bool check(int a, int b, int c) {
int cou = 0;
for (int i = a; i <= (b); ++i) {
cou += (t[i] < t[c]);
}
return cou == c - a;
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= (n); ++i) {
int x;
cin >> t[i];
}
for (int i = 1; i <= (m); ++i) {
int a, b, c;
cin >> a >> b >> c;
if (check(a, b, c)) {
cout << "Yes" << '\n';
} else {
cout << "No" << '\n';
}
}
return;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
test = 1;
while (test--) {
solve();
}
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
while (*sdbg != ',') cerr << *sdbg++;
cerr << "=" << h << ",";
_dbg(sdbg + 1, a...);
}
int test;
int n, m;
int t[500007];
bool check(int a, int b, int c) {
int cou = 0;
for (int i = a; i <= (b); ++i) {
cou += (t[i] < t[c]);
}
return cou == c - a;
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= (n); ++i) {
int x;
cin >> t[i];
}
for (int i = 1; i <= (m); ++i) {
int a, b, c;
cin >> a >> b >> c;
if (check(a, b, c)) {
cout << "Yes" << '\n';
} else {
cout << "No" << '\n';
}
}
return;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
test = 1;
while (test--) {
solve();
}
return 0;
}
``` |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int* A = new int[n];
for (int i = 0; i < n; i++) {
cin >> A[i];
}
int l, r, p;
for (int i = 0; i < m; i++) {
cin >> l >> r >> p;
if (p < l)
cout << "No" << endl;
else if (p > r)
cout << "No" << endl;
else {
int x = A[p - 1];
int count = 0;
for (int j = l; j <= r; j++) {
if (A[j - 1] < x) {
count++;
}
}
if (l + count == p)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int* A = new int[n];
for (int i = 0; i < n; i++) {
cin >> A[i];
}
int l, r, p;
for (int i = 0; i < m; i++) {
cin >> l >> r >> p;
if (p < l)
cout << "No" << endl;
else if (p > r)
cout << "No" << endl;
else {
int x = A[p - 1];
int count = 0;
for (int j = l; j <= r; j++) {
if (A[j - 1] < x) {
count++;
}
}
if (l + count == p)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int ar[10005];
int arr[10005];
int pos[10005];
void swap(int &x, int &y) {
int t = x;
x = y;
y = t;
}
int partition(int l, int r, int x) {
int i;
swap(arr[x], arr[r]);
i = l;
for (int j = l; j <= r - 1; j++) {
if (arr[j] <= arr[r]) {
swap(arr[i], arr[j]);
i++;
}
}
swap(arr[i], arr[r]);
return i;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> ar[i];
pos[ar[i]] = i;
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
if (x > r || x < l) {
cout << "Yes\n";
continue;
}
memcpy(arr, ar, sizeof(ar));
int x1 = partition(l, r, x);
if (x1 == x) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int ar[10005];
int arr[10005];
int pos[10005];
void swap(int &x, int &y) {
int t = x;
x = y;
y = t;
}
int partition(int l, int r, int x) {
int i;
swap(arr[x], arr[r]);
i = l;
for (int j = l; j <= r - 1; j++) {
if (arr[j] <= arr[r]) {
swap(arr[i], arr[j]);
i++;
}
}
swap(arr[i], arr[r]);
return i;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> ar[i];
pos[ar[i]] = i;
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
if (x > r || x < l) {
cout << "Yes\n";
continue;
}
memcpy(arr, ar, sizeof(ar));
int x1 = partition(l, r, x);
if (x1 == x) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int poz[10001];
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
poz[a[i]] = i;
}
int l, r, x;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
l--, r--, x--;
int br = 0;
for (int j = l; j <= r; j++) {
if (a[j] < a[x]) br++;
}
if (x - l == br) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int poz[10001];
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
poz[a[i]] = i;
}
int l, r, x;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
l--, r--, x--;
int br = 0;
for (int j = l; j <= r; j++) {
if (a[j] < a[x]) br++;
}
if (x - l == br) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
inline int IN() {
int x = 0, f = 1;
char ch;
for (ch = (getchar()); ch > '9' || ch < '0'; ch = (getchar()))
if (ch == '-') f = -1;
for (; ch >= '0' && ch <= '9'; ch = (getchar())) (x *= 10) += ch - '0';
return x * f;
}
int i, j, k, l, n, m, x, y, z, a[10005], t;
int main() {
n = IN();
m = IN();
for (i = 1; i <= n; i++) a[i] = IN();
for (i = 1; i <= m; i++) {
x = IN();
y = IN();
z = IN();
t = 0;
for (j = x; j <= y; j++)
if (a[j] < a[z]) t++;
if (x + t == z)
puts("Yes");
else
puts("No");
}
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline int IN() {
int x = 0, f = 1;
char ch;
for (ch = (getchar()); ch > '9' || ch < '0'; ch = (getchar()))
if (ch == '-') f = -1;
for (; ch >= '0' && ch <= '9'; ch = (getchar())) (x *= 10) += ch - '0';
return x * f;
}
int i, j, k, l, n, m, x, y, z, a[10005], t;
int main() {
n = IN();
m = IN();
for (i = 1; i <= n; i++) a[i] = IN();
for (i = 1; i <= m; i++) {
x = IN();
y = IN();
z = IN();
t = 0;
for (j = x; j <= y; j++)
if (a[j] < a[z]) t++;
if (x + t == z)
puts("Yes");
else
puts("No");
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> arr;
int n, m, temp;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &temp);
arr.push_back(temp);
}
for (int i = 0; i < m; i++) {
int l, r, ind;
scanf("%d %d %d", &l, &r, &ind);
vector<int> temp, freq;
freq.assign(n + 1, 0);
for (int j = l - 1; j < r; j++) freq[arr[j]]++;
for (int j = 0; j < n + 1; j++) {
if (freq[j] == 1) temp.push_back(j);
}
int ind2 = ind - l;
(temp[ind2] == arr[ind - 1]) ? printf("Yes\n") : printf("No\n");
}
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> arr;
int n, m, temp;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &temp);
arr.push_back(temp);
}
for (int i = 0; i < m; i++) {
int l, r, ind;
scanf("%d %d %d", &l, &r, &ind);
vector<int> temp, freq;
freq.assign(n + 1, 0);
for (int j = l - 1; j < r; j++) freq[arr[j]]++;
for (int j = 0; j < n + 1; j++) {
if (freq[j] == 1) temp.push_back(j);
}
int ind2 = ind - l;
(temp[ind2] == arr[ind - 1]) ? printf("Yes\n") : printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
int a[N], sorted[N], n, m, sum[20][N], tree[20][N];
inline void build(int deep, int l, int r) {
int i, mid = (l + r) >> 1, lm = mid - l + 1, lp = l, rp = mid + 1;
for (i = l; i <= mid; i++)
if (sorted[i] > sorted[mid]) lm--;
for (i = l; i <= r; i++) {
if (i == l)
sum[deep][i] = 0;
else
sum[deep][i] = sum[deep][i - 1];
if (tree[deep][i] == sorted[mid]) {
if (lm) {
lm--;
sum[deep][i]++;
tree[deep + 1][lp++] = tree[deep][i];
} else
tree[deep + 1][rp++] = tree[deep][i];
} else if (tree[deep][i] > sorted[mid]) {
sum[deep][i]++;
tree[deep + 1][lp++] = tree[deep][i];
} else
tree[deep + 1][rp++] = tree[deep][i];
}
if (l != r) {
build(deep + 1, l, mid);
build(deep + 1, mid + 1, r);
}
}
int ask(int deep, int l, int r, int ql, int qr, int k) {
int s, ss, mid = (l + r) >> 1;
if (l == r) return tree[deep][l];
if (l == ql) {
s = 0;
ss = sum[deep][qr];
} else {
s = sum[deep][ql - 1];
ss = sum[deep][qr] - s;
}
if (k <= ss)
return ask(deep + 1, l, mid, l + s, l + s + ss - 1, k);
else
return ask(deep + 1, mid + 1, r, mid - l + 1 + ql - s,
mid - l + 1 + qr - s - ss, k - ss);
}
inline bool cmp(int a, int b) { return a > b; }
inline int read() {
int x = 0;
char ch = getchar();
bool positive = 1;
for (; !isdigit(ch); ch = getchar())
if (ch == '-') positive = 0;
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(int a) {
if (a >= 10) write(a / 10);
putchar('0' + a % 10);
}
int main() {
n = read();
m = read();
for (int i = 1; i <= n; i++) a[i] = tree[0][i] = sorted[i] = read();
sort(sorted + 1, sorted + 1 + n, cmp);
build(0, 1, n);
while (m--) {
int s1 = read(), s2 = read(), s3 = read();
if (ask(0, 1, n, s1, s2, s2 - s3 + 1) == a[s3])
puts("Yes");
else
puts("No");
}
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
int a[N], sorted[N], n, m, sum[20][N], tree[20][N];
inline void build(int deep, int l, int r) {
int i, mid = (l + r) >> 1, lm = mid - l + 1, lp = l, rp = mid + 1;
for (i = l; i <= mid; i++)
if (sorted[i] > sorted[mid]) lm--;
for (i = l; i <= r; i++) {
if (i == l)
sum[deep][i] = 0;
else
sum[deep][i] = sum[deep][i - 1];
if (tree[deep][i] == sorted[mid]) {
if (lm) {
lm--;
sum[deep][i]++;
tree[deep + 1][lp++] = tree[deep][i];
} else
tree[deep + 1][rp++] = tree[deep][i];
} else if (tree[deep][i] > sorted[mid]) {
sum[deep][i]++;
tree[deep + 1][lp++] = tree[deep][i];
} else
tree[deep + 1][rp++] = tree[deep][i];
}
if (l != r) {
build(deep + 1, l, mid);
build(deep + 1, mid + 1, r);
}
}
int ask(int deep, int l, int r, int ql, int qr, int k) {
int s, ss, mid = (l + r) >> 1;
if (l == r) return tree[deep][l];
if (l == ql) {
s = 0;
ss = sum[deep][qr];
} else {
s = sum[deep][ql - 1];
ss = sum[deep][qr] - s;
}
if (k <= ss)
return ask(deep + 1, l, mid, l + s, l + s + ss - 1, k);
else
return ask(deep + 1, mid + 1, r, mid - l + 1 + ql - s,
mid - l + 1 + qr - s - ss, k - ss);
}
inline bool cmp(int a, int b) { return a > b; }
inline int read() {
int x = 0;
char ch = getchar();
bool positive = 1;
for (; !isdigit(ch); ch = getchar())
if (ch == '-') positive = 0;
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(int a) {
if (a >= 10) write(a / 10);
putchar('0' + a % 10);
}
int main() {
n = read();
m = read();
for (int i = 1; i <= n; i++) a[i] = tree[0][i] = sorted[i] = read();
sort(sorted + 1, sorted + 1 + n, cmp);
build(0, 1, n);
while (m--) {
int s1 = read(), s2 = read(), s3 = read();
if (ask(0, 1, n, s1, s2, s2 - s3 + 1) == a[s3])
puts("Yes");
else
puts("No");
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i;
scanf("%d %d", &n, &m);
int p[n];
for (i = 0; i < n; i++) scanf("%d", &p[i]);
for (i = 1; i <= m; i++) {
int l, r, x, j, cnt = 0;
scanf("%d %d %d", &l, &r, &x);
for (j = l - 1; j < r; j++) {
if (p[j] < p[x - 1]) cnt++;
}
puts((p[x - 1] == p[l + cnt - 1]) ? "Yes" : "No");
}
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i;
scanf("%d %d", &n, &m);
int p[n];
for (i = 0; i < n; i++) scanf("%d", &p[i]);
for (i = 1; i <= m; i++) {
int l, r, x, j, cnt = 0;
scanf("%d %d %d", &l, &r, &x);
for (j = l - 1; j < r; j++) {
if (p[j] < p[x - 1]) cnt++;
}
puts((p[x - 1] == p[l + cnt - 1]) ? "Yes" : "No");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int b[100000], a[100000];
int main() {
long long n, m;
while (cin >> n >> m) {
for (int i = 0; i < n; i++) cin >> a[i], b[a[i]] = i, b[a[i]]++;
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
x--;
x = a[x];
l--, r--;
int count = 0;
for (int j = l; j <= r; j++)
if (a[j] > x) count++;
if (r - count + 1 == b[x])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int b[100000], a[100000];
int main() {
long long n, m;
while (cin >> n >> m) {
for (int i = 0; i < n; i++) cin >> a[i], b[a[i]] = i, b[a[i]]++;
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
x--;
x = a[x];
l--, r--;
int count = 0;
for (int j = l; j <= r; j++)
if (a[j] > x) count++;
if (r - count + 1 == b[x])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int b[n];
for (int i = 0; i < n; i++) {
cin >> b[i];
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
if (x > r || x < l) {
cout << "Yes\n";
continue;
}
l--;
r--;
x--;
int c = 0;
for (int i = l; i <= r; i++) {
if (i == x) continue;
if (b[i] < b[x]) c++;
}
if (x == l + c)
cout << "Yes\n";
else
cout << "No\n";
}
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int b[n];
for (int i = 0; i < n; i++) {
cin >> b[i];
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
if (x > r || x < l) {
cout << "Yes\n";
continue;
}
l--;
r--;
x--;
int c = 0;
for (int i = l; i <= r; i++) {
if (i == x) continue;
if (b[i] < b[x]) c++;
}
if (x == l + c)
cout << "Yes\n";
else
cout << "No\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
struct data {
int value;
int index;
};
struct data A[10001];
int P[10001], B[100001];
int comp(const void *a, const void *b) {
return (*(struct data *)a).value - (*(struct data *)b).value;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> P[i];
A[i].value = P[i];
A[i].index = i;
}
qsort(A, n, sizeof(struct data), comp);
for (int i = 0; i < m; i++) {
int l, r, x, k;
cin >> l >> r >> x;
k = l - 1;
for (int j = 0; j < n; j++) {
if (A[j].index < r && A[j].index >= l - 1) {
B[k++] = A[j].value;
}
}
if (B[x - 1] == P[x - 1])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct data {
int value;
int index;
};
struct data A[10001];
int P[10001], B[100001];
int comp(const void *a, const void *b) {
return (*(struct data *)a).value - (*(struct data *)b).value;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> P[i];
A[i].value = P[i];
A[i].index = i;
}
qsort(A, n, sizeof(struct data), comp);
for (int i = 0; i < m; i++) {
int l, r, x, k;
cin >> l >> r >> x;
k = l - 1;
for (int j = 0; j < n; j++) {
if (A[j].index < r && A[j].index >= l - 1) {
B[k++] = A[j].value;
}
}
if (B[x - 1] == P[x - 1])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int NUM = 2e5 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int num_tests = 1;
while (num_tests-- > 0) {
int n, m;
cin >> n >> m;
vector<int> p(n);
for (long long int i = 0; i < n; i++) cin >> p[i];
map<int, int> orig;
for (long long int i = 0; i < n; i++) orig[p[i]] = i;
while (m--) {
int l, r, x;
cin >> l >> r >> x;
int num = p[x - 1];
int ans = 0;
for (long long int i = l - 1; i < r; i++) {
if (p[i] < num) ans++;
}
if (l + ans == x)
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
}
}
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int NUM = 2e5 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int num_tests = 1;
while (num_tests-- > 0) {
int n, m;
cin >> n >> m;
vector<int> p(n);
for (long long int i = 0; i < n; i++) cin >> p[i];
map<int, int> orig;
for (long long int i = 0; i < n; i++) orig[p[i]] = i;
while (m--) {
int l, r, x;
cin >> l >> r >> x;
int num = p[x - 1];
int ans = 0;
for (long long int i = l - 1; i < r; i++) {
if (p[i] < num) ans++;
}
if (l + ans == x)
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 5;
int s[MAXN + 5];
int n, m;
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
for (int i = 1; i <= m; i++) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
int tot = s[x], sum = 0;
for (int j = l; j <= r; j++)
if (s[j] < tot) sum++;
if (sum == x - l)
printf("Yes\n");
else
printf("No\n");
}
}
| ### Prompt
Create a solution in Cpp for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 5;
int s[MAXN + 5];
int n, m;
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
for (int i = 1; i <= m; i++) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
int tot = s[x], sum = 0;
for (int j = l; j <= r; j++)
if (s[j] < tot) sum++;
if (sum == x - l)
printf("Yes\n");
else
printf("No\n");
}
}
``` |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
long long a[n + 5], i;
for (i = 1; i <= n; i++) cin >> a[i];
while (m--) {
long long l, r, x;
cin >> l >> r >> x;
long long cnt = 0;
for (i = l; i <= r; i++)
if (a[i] < a[x]) cnt++;
long long y = cnt + 1;
y = l + y - 1;
if (y != x)
cout << "No\n";
else
cout << "Yes\n";
}
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
long long a[n + 5], i;
for (i = 1; i <= n; i++) cin >> a[i];
while (m--) {
long long l, r, x;
cin >> l >> r >> x;
long long cnt = 0;
for (i = l; i <= r; i++)
if (a[i] < a[x]) cnt++;
long long y = cnt + 1;
y = l + y - 1;
if (y != x)
cout << "No\n";
else
cout << "Yes\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 100;
int ar[MAXN];
int main() {
#pragma warning(disable : 4996)
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &ar[i]);
for (int i = 0; i < m; i++) {
int l, r, x, c = 0;
scanf("%d%d%d", &l, &r, &x);
l--;
r--;
x--;
for (int j = l; j <= r; j++) {
if (ar[j] < ar[x]) c++;
}
if (x - l == c)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 100;
int ar[MAXN];
int main() {
#pragma warning(disable : 4996)
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &ar[i]);
for (int i = 0; i < m; i++) {
int l, r, x, c = 0;
scanf("%d%d%d", &l, &r, &x);
l--;
r--;
x--;
for (int j = l; j <= r; j++) {
if (ar[j] < ar[x]) c++;
}
if (x - l == c)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
class Bigint {
public:
int c;
int a[100];
Bigint() {
c = 1;
memset(a, 0, sizeof(a));
}
Bigint(int x) {
if (!x) {
c = 1;
memset(a, 0, sizeof(a));
return;
}
c = 0;
memset(a, 0, sizeof(a));
while (x != 0) {
a[c++] = x % 10000;
x /= 10000;
}
}
Bigint operator+(const Bigint &b) const {
Bigint result;
result.c = max(c, b.c);
for (int i = 0; i < result.c; i++) {
result.a[i] += a[i] + b.a[i];
result.a[i + 1] = result.a[i] / 10000;
result.a[i] %= 10000;
}
if (result.a[result.c] > 0) {
result.c++;
}
return result;
}
Bigint operator*(const Bigint &b) const {
Bigint result;
result.c = c + b.c;
for (int i = 0; i < c; i++)
for (int j = 0; j < b.c; j++) {
result.a[i + j] += a[i] * b.a[j];
}
int d = 0;
for (int i = 0; i < result.c; i++) {
result.a[i] += d;
d = result.a[i] / 10000;
result.a[i] %= 10000;
}
if (d) result.a[result.c++] = d;
while (result.a[result.c - 1] == 0) result.c--;
return result;
}
Bigint operator-(const Bigint &b) const {
Bigint result;
result.c = max(c, b.c);
for (int i = 0; i < result.c; i++) {
result.a[i] += a[i] - b.a[i];
if (result.a[i] < 0) result.a[i + 1]--, result.a[i] += 10000;
}
while (result.a[result.c - 1] == 0) result.c--;
return result;
}
void print() const {
printf("%d", a[c - 1]);
for (int i = c - 2; i >= 0; i--) {
printf("%04d", a[i]);
}
}
};
const int maxn = 10005;
int n, m;
int a[maxn];
int main() {
scanf("%d%d", &n, &m);
for (int(i) = 1; (i) <= n; i++) scanf("%d", &a[i]);
while (m--) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int cnt = 1;
for (int i = l; i <= r; i++)
if (a[i] < a[x]) cnt++;
if (cnt != x - l + 1)
puts("No");
else
puts("Yes");
}
return 0;
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
class Bigint {
public:
int c;
int a[100];
Bigint() {
c = 1;
memset(a, 0, sizeof(a));
}
Bigint(int x) {
if (!x) {
c = 1;
memset(a, 0, sizeof(a));
return;
}
c = 0;
memset(a, 0, sizeof(a));
while (x != 0) {
a[c++] = x % 10000;
x /= 10000;
}
}
Bigint operator+(const Bigint &b) const {
Bigint result;
result.c = max(c, b.c);
for (int i = 0; i < result.c; i++) {
result.a[i] += a[i] + b.a[i];
result.a[i + 1] = result.a[i] / 10000;
result.a[i] %= 10000;
}
if (result.a[result.c] > 0) {
result.c++;
}
return result;
}
Bigint operator*(const Bigint &b) const {
Bigint result;
result.c = c + b.c;
for (int i = 0; i < c; i++)
for (int j = 0; j < b.c; j++) {
result.a[i + j] += a[i] * b.a[j];
}
int d = 0;
for (int i = 0; i < result.c; i++) {
result.a[i] += d;
d = result.a[i] / 10000;
result.a[i] %= 10000;
}
if (d) result.a[result.c++] = d;
while (result.a[result.c - 1] == 0) result.c--;
return result;
}
Bigint operator-(const Bigint &b) const {
Bigint result;
result.c = max(c, b.c);
for (int i = 0; i < result.c; i++) {
result.a[i] += a[i] - b.a[i];
if (result.a[i] < 0) result.a[i + 1]--, result.a[i] += 10000;
}
while (result.a[result.c - 1] == 0) result.c--;
return result;
}
void print() const {
printf("%d", a[c - 1]);
for (int i = c - 2; i >= 0; i--) {
printf("%04d", a[i]);
}
}
};
const int maxn = 10005;
int n, m;
int a[maxn];
int main() {
scanf("%d%d", &n, &m);
for (int(i) = 1; (i) <= n; i++) scanf("%d", &a[i]);
while (m--) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int cnt = 1;
for (int i = l; i <= r; i++)
if (a[i] < a[x]) cnt++;
if (cnt != x - l + 1)
puts("No");
else
puts("Yes");
}
return 0;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 10005;
int n, m, number;
int p[MAX_N], l, r, x, ile;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
ile = 0;
number = p[x - 1];
for (int j = l - 1; j < r; j++) {
if (p[j] < number) {
ile++;
}
}
if (ile == x - l) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 10005;
int n, m, number;
int p[MAX_N], l, r, x, ile;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
ile = 0;
number = p[x - 1];
for (int j = l - 1; j < r; j++) {
if (p[j] < number) {
ile++;
}
}
if (ile == x - l) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
``` |
#include <bits/stdc++.h>
int main() {
int l, r, x, n, m, i, j;
scanf("%d%d", &n, &m);
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
a[i]--;
}
while (m--) {
scanf("%d%d%d", &l, &r, &x);
l--;
r--;
x--;
int c = 0;
for (i = l; i <= r; i++) {
if (a[i] < a[x]) c++;
}
if (c == (x - l))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int l, r, x, n, m, i, j;
scanf("%d%d", &n, &m);
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
a[i]--;
}
while (m--) {
scanf("%d%d%d", &l, &r, &x);
l--;
r--;
x--;
int c = 0;
for (i = l; i <= r; i++) {
if (a[i] < a[x]) c++;
}
if (c == (x - l))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[10004];
int n;
int main() {
int m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
if (l == r || x > r || x < l)
cout << "Yes\n";
else {
int cnt = 0, cnt1 = 0;
int mx = a[x - 1];
for (int i = l - 1; i < r; i++) {
if (a[i] > a[x - 1] && i <= x - 1)
cnt++;
else if (a[i] < a[x - 1] && i >= x)
cnt1++;
}
if (cnt1 - cnt == 0)
cout << "Yes\n";
else
cout << "No\n";
}
}
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10004];
int n;
int main() {
int m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
if (l == r || x > r || x < l)
cout << "Yes\n";
else {
int cnt = 0, cnt1 = 0;
int mx = a[x - 1];
for (int i = l - 1; i < r; i++) {
if (a[i] > a[x - 1] && i <= x - 1)
cnt++;
else if (a[i] < a[x - 1] && i >= x)
cnt1++;
}
if (cnt1 - cnt == 0)
cout << "Yes\n";
else
cout << "No\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void fun() {
long long n, m;
cin >> n >> m;
vector<long long> v(n), dum(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
dum[i] = v[i];
}
for (long long i = 0; i < m; i++) {
long long l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
long long left = 0, right = 0;
for (long long j = l; j < x; j++) {
if (v[j] > v[x]) left++;
}
for (long long j = x + 1; j <= r; j++) {
if (v[j] < v[x]) right++;
}
if (left == right) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
dum = v;
}
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
long long t;
t = 1;
for (long long i = 0; i < t; i++) fun();
}
| ### Prompt
Create a solution in cpp for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void fun() {
long long n, m;
cin >> n >> m;
vector<long long> v(n), dum(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
dum[i] = v[i];
}
for (long long i = 0; i < m; i++) {
long long l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
long long left = 0, right = 0;
for (long long j = l; j < x; j++) {
if (v[j] > v[x]) left++;
}
for (long long j = x + 1; j <= r; j++) {
if (v[j] < v[x]) right++;
}
if (left == right) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
dum = v;
}
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
long long t;
t = 1;
for (long long i = 0; i < t; i++) fun();
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long power(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b & 1) ans *= a;
a = a * a;
b >>= 1;
}
return ans;
}
long long powm(long long a, long long b) {
a %= MOD;
long long ans = 1;
while (b > 0) {
if (b & 1) ans = (ans * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return ans;
}
void IO() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
IO();
;
int n, m;
cin >> n >> m;
vector<int> P(n);
for (int &x : P) cin >> x;
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
if (x < l || x > r) {
cout << "Yes\n";
continue;
}
int a = 0, b = 0;
for (int i = l; i <= r; i++) {
if (P[i] < P[x])
a++;
else
b++;
}
if (x < l + a || x > l + a)
cout << "No\n";
else
cout << "Yes\n";
}
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long power(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b & 1) ans *= a;
a = a * a;
b >>= 1;
}
return ans;
}
long long powm(long long a, long long b) {
a %= MOD;
long long ans = 1;
while (b > 0) {
if (b & 1) ans = (ans * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return ans;
}
void IO() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
IO();
;
int n, m;
cin >> n >> m;
vector<int> P(n);
for (int &x : P) cin >> x;
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
if (x < l || x > r) {
cout << "Yes\n";
continue;
}
int a = 0, b = 0;
for (int i = l; i <= r; i++) {
if (P[i] < P[x])
a++;
else
b++;
}
if (x < l + a || x > l + a)
cout << "No\n";
else
cout << "Yes\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long i, j, x, n, m, l, r;
cin >> n >> m;
vector<long long> v;
for (i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
for (i = 0; i < m; i++) {
cin >> l >> r >> x;
long long c = 0;
if (x < l || x > r) {
cout << "Yes\n";
continue;
}
for (j = l - 1; j < r; j++) {
if (v[j] < v[x - 1]) {
c++;
}
}
if (c == (x - l)) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long i, j, x, n, m, l, r;
cin >> n >> m;
vector<long long> v;
for (i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
for (i = 0; i < m; i++) {
cin >> l >> r >> x;
long long c = 0;
if (x < l || x > r) {
cout << "Yes\n";
continue;
}
for (j = l - 1; j < r; j++) {
if (v[j] < v[x - 1]) {
c++;
}
}
if (c == (x - l)) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, i, j, n, a[100000], x, y, index, num, l, r, count, count1,
temp;
vector<int> vect;
cin >> n >> t;
for (i = 0; i < n; i++) {
cin >> a[i];
}
while (t > 0) {
count = 0;
count1 = 0;
cin >> x >> y >> index;
index = index - 1;
x = x - 1;
y = y - 1;
if (x <= index && index <= y) {
for (i = index - 1; i >= x; i--) {
if (a[index] < a[i]) {
count++;
}
}
for (i = index + 1; i <= y; i++) {
if (a[index] > a[i]) {
count1++;
}
}
if (count == count1) {
temp = 1;
} else {
temp = 0;
}
} else {
temp = 1;
}
if (temp == 1) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
t--;
}
return 0;
}
| ### Prompt
Generate a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, i, j, n, a[100000], x, y, index, num, l, r, count, count1,
temp;
vector<int> vect;
cin >> n >> t;
for (i = 0; i < n; i++) {
cin >> a[i];
}
while (t > 0) {
count = 0;
count1 = 0;
cin >> x >> y >> index;
index = index - 1;
x = x - 1;
y = y - 1;
if (x <= index && index <= y) {
for (i = index - 1; i >= x; i--) {
if (a[index] < a[i]) {
count++;
}
}
for (i = index + 1; i <= y; i++) {
if (a[index] > a[i]) {
count1++;
}
}
if (count == count1) {
temp = 1;
} else {
temp = 0;
}
} else {
temp = 1;
}
if (temp == 1) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
t--;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, l, r, x;
cin >> n >> m;
vector<int> A(n);
for (int i = 0; i < n; i++) cin >> A[i];
while (m--) {
cin >> l >> r >> x;
l--, x--, r--;
int j = 0;
for (int i = l; i <= r; i++) j += A[i] < A[x];
cout << (l + j == x ? "Yes\n" : "No\n");
}
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, l, r, x;
cin >> n >> m;
vector<int> A(n);
for (int i = 0; i < n; i++) cin >> A[i];
while (m--) {
cin >> l >> r >> x;
l--, x--, r--;
int j = 0;
for (int i = l; i <= r; i++) j += A[i] < A[x];
cout << (l + j == x ? "Yes\n" : "No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[10010];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
while (m--) {
int l, r, p;
scanf("%d%d%d", &l, &r, &p);
if (p < l || p > r) {
printf("Yes\n");
continue;
}
int cnt = 0;
for (int i = l - 1; i < r; i++) {
if (a[i] < a[p - 1]) cnt++;
}
if (a[l + cnt - 1] == a[p - 1])
printf("Yes\n");
else
printf("No\n");
}
cin >> n;
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10010];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
while (m--) {
int l, r, p;
scanf("%d%d%d", &l, &r, &p);
if (p < l || p > r) {
printf("Yes\n");
continue;
}
int cnt = 0;
for (int i = l - 1; i < r; i++) {
if (a[i] < a[p - 1]) cnt++;
}
if (a[l + cnt - 1] == a[p - 1])
printf("Yes\n");
else
printf("No\n");
}
cin >> n;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int a[100009], b[100009];
int main() {
long long int i, j, k, m, n, l, r, p, cont = 0;
cin >> m >> n;
for (i = 0; i < m; i++) {
cin >> a[i];
b[i] = a[i];
}
for (j = 0; j < n; j++) {
cont = 0;
cin >> l >> r >> p;
for (i = l - 1; i < r; i++) {
if (a[i] < a[p - 1]) cont++;
}
p -= l;
if (p == cont)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int a[100009], b[100009];
int main() {
long long int i, j, k, m, n, l, r, p, cont = 0;
cin >> m >> n;
for (i = 0; i < m; i++) {
cin >> a[i];
b[i] = a[i];
}
for (j = 0; j < n; j++) {
cont = 0;
cin >> l >> r >> p;
for (i = l - 1; i < r; i++) {
if (a[i] < a[p - 1]) cont++;
}
p -= l;
if (p == cont)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
template <class T>
int getbit(T x, int pos) {
return (x >> (pos - 1)) & 1;
}
template <class T>
void turn_on(T &x, int pos) {
x = x | ((T)1 << (pos - 1));
}
template <class T>
void turn_off(T &x, int pos) {
x = x & ~((T)1 << (pos - 1));
}
template <class T>
T sqr(T a) {
return a * a;
}
int n, m, a[11000], pos[11000];
int main() {
scanf("%d %d", &n, &m);
for (int i = int(1); i <= int(n); ++i) {
scanf("%d", &a[i]);
pos[a[i]] = i;
}
for (int i = int(1); i <= int(m); ++i) {
int cnt = 0;
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
if (x < l || x > r) {
cout << "No\n";
continue;
}
for (int i = int(x + 1); i <= int(r); ++i) {
if (a[i] < a[x]) cnt++;
}
for (int i = int(x - 1); i >= int(l); --i) {
if (a[i] > a[x]) cnt--;
}
if (cnt == 0) {
cout << "Yes\n";
} else
cout << "No\n";
}
return 0;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
template <class T>
int getbit(T x, int pos) {
return (x >> (pos - 1)) & 1;
}
template <class T>
void turn_on(T &x, int pos) {
x = x | ((T)1 << (pos - 1));
}
template <class T>
void turn_off(T &x, int pos) {
x = x & ~((T)1 << (pos - 1));
}
template <class T>
T sqr(T a) {
return a * a;
}
int n, m, a[11000], pos[11000];
int main() {
scanf("%d %d", &n, &m);
for (int i = int(1); i <= int(n); ++i) {
scanf("%d", &a[i]);
pos[a[i]] = i;
}
for (int i = int(1); i <= int(m); ++i) {
int cnt = 0;
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
if (x < l || x > r) {
cout << "No\n";
continue;
}
for (int i = int(x + 1); i <= int(r); ++i) {
if (a[i] < a[x]) cnt++;
}
for (int i = int(x - 1); i >= int(l); --i) {
if (a[i] > a[x]) cnt--;
}
if (cnt == 0) {
cout << "Yes\n";
} else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
return x.size();
}
const int INF = ~(1 << 31);
const double pi = acos(-1);
const double EPS = 1e-9;
int main() {
cin.sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> arr(n);
int pos[1000000];
for (int i = (0); i < (n); i++) cin >> arr[i];
for (int i = (0); i < (m); i++) {
int l, r, x;
cin >> l >> r >> x;
l--, r--;
x--;
if (l <= x && x <= r) {
int cnt = 0;
for (int i = (l); i < (r + 1); i++)
if (arr[i] < arr[x]) cnt++;
if (l + cnt != x)
cout << "No" << endl;
else
cout << "Yes" << endl;
} else {
cout << "Yes" << endl;
}
}
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
return x.size();
}
const int INF = ~(1 << 31);
const double pi = acos(-1);
const double EPS = 1e-9;
int main() {
cin.sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> arr(n);
int pos[1000000];
for (int i = (0); i < (n); i++) cin >> arr[i];
for (int i = (0); i < (m); i++) {
int l, r, x;
cin >> l >> r >> x;
l--, r--;
x--;
if (l <= x && x <= r) {
int cnt = 0;
for (int i = (l); i < (r + 1); i++)
if (arr[i] < arr[x]) cnt++;
if (l + cnt != x)
cout << "No" << endl;
else
cout << "Yes" << endl;
} else {
cout << "Yes" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007ll;
int arr[100005];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
while (m--) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
int cnt = 0;
for (int i = l; i <= r; i++) {
if (arr[i] < arr[x]) cnt++;
}
if (l + cnt == x)
puts("Yes");
else
puts("No");
}
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007ll;
int arr[100005];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
while (m--) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
int cnt = 0;
for (int i = l; i <= r; i++) {
if (arr[i] < arr[x]) cnt++;
}
if (l + cnt == x)
puts("Yes");
else
puts("No");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool b;
long long ans, cnt, arr[100000], sum;
string num_to_string(int num) {
stringstream ss;
ss << num;
return ss.str();
}
void O_o() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
int main() {
O_o();
int n, m, x, y, z;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> arr[i];
while (m--) {
cnt = 0;
cin >> x >> y >> z;
x--;
y--;
z--;
for (int i = x; i <= y; i++)
if (arr[i] < arr[z]) cnt++;
if (cnt == z - x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool b;
long long ans, cnt, arr[100000], sum;
string num_to_string(int num) {
stringstream ss;
ss << num;
return ss.str();
}
void O_o() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
int main() {
O_o();
int n, m, x, y, z;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> arr[i];
while (m--) {
cnt = 0;
cin >> x >> y >> z;
x--;
y--;
z--;
for (int i = x; i <= y; i++)
if (arr[i] < arr[z]) cnt++;
if (cnt == z - x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool place(int p[], int l, int r, int x) {
if (l > x || r < x)
return true;
else {
int delta = 0;
for (int i = l; i <= r; i++)
if (p[i] > p[x]) delta++;
if (x == (r - delta)) return true;
return false;
}
}
int main() {
int n, m;
cin >> n >> m;
int *p = new int[n];
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
if (place(p, l - 1, r - 1, x - 1))
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool place(int p[], int l, int r, int x) {
if (l > x || r < x)
return true;
else {
int delta = 0;
for (int i = l; i <= r; i++)
if (p[i] > p[x]) delta++;
if (x == (r - delta)) return true;
return false;
}
}
int main() {
int n, m;
cin >> n >> m;
int *p = new int[n];
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
if (place(p, l - 1, r - 1, x - 1))
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
if (n == 1) {
return false;
}
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
vector<long long> primeFactors(long long n) {
vector<long long> a;
while (n % 2 == 0) {
a.push_back(2);
n = n / 2;
}
for (long long i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
a.push_back(i);
n = n / i;
}
}
if (n > 2) a.push_back(n);
return a;
}
long long ceil(const long long &a, const long long &b) {
if (a % b == 0) return a / b;
return a / b + 1;
}
bool perm(vector<long long> neww) {
long long req = neww.size();
sort(neww.begin(), neww.end());
for (long long i = 1; i <= req; i++) {
if (neww[i - 1] != i) {
return false;
}
}
return true;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
while (t--) {
long long n, m;
cin >> n >> m;
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
while (m--) {
long long l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
long long i = x - 1;
long long j = x + 1;
long long count_s = 0;
long long count_l = 0;
bool flag = true;
while (i >= l || j <= r) {
if (i >= l && v[i] > v[x]) {
count_l++;
}
if (j <= r && v[j] < v[x]) {
count_s++;
}
i--;
j++;
}
if (count_s != count_l) {
flag = false;
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
if (n == 1) {
return false;
}
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
vector<long long> primeFactors(long long n) {
vector<long long> a;
while (n % 2 == 0) {
a.push_back(2);
n = n / 2;
}
for (long long i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
a.push_back(i);
n = n / i;
}
}
if (n > 2) a.push_back(n);
return a;
}
long long ceil(const long long &a, const long long &b) {
if (a % b == 0) return a / b;
return a / b + 1;
}
bool perm(vector<long long> neww) {
long long req = neww.size();
sort(neww.begin(), neww.end());
for (long long i = 1; i <= req; i++) {
if (neww[i - 1] != i) {
return false;
}
}
return true;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
while (t--) {
long long n, m;
cin >> n >> m;
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
while (m--) {
long long l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
long long i = x - 1;
long long j = x + 1;
long long count_s = 0;
long long count_l = 0;
bool flag = true;
while (i >= l || j <= r) {
if (i >= l && v[i] > v[x]) {
count_l++;
}
if (j <= r && v[j] < v[x]) {
count_s++;
}
i--;
j++;
}
if (count_s != count_l) {
flag = false;
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main() {
int n, m, l, r, x, temp;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
int temp = a[x];
int cnt = 0;
for (int j = l; j <= r; j++) {
if (a[j] < temp) cnt++;
}
if (cnt == x - l)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main() {
int n, m, l, r, x, temp;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
int temp = a[x];
int cnt = 0;
for (int j = l; j <= r; j++) {
if (a[j] < temp) cnt++;
}
if (cnt == x - l)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
vector<int> a, c;
int main() {
int n, m;
cin >> n >> m;
a.resize(n);
for (__typeof((n)) i = (0); i < (n); i += 1) {
cin >> a[i];
}
c = a;
int z = sqrt(n);
vector<vector<int> > b(z + 1);
vector<pair<int, int> > d(z + 1);
for (__typeof((z)) i = (0); i < (z); i += 1) {
sort(c.begin() + i * z, c.begin() + (i + 1) * z);
b[i].resize(z);
for (__typeof(((i + 1) * z)) j = (i * z); j < ((i + 1) * z); j += 1) {
b[i][j - i * z] = c[j];
}
d[i] = make_pair(i * z, (i + 1) * z);
}
if (z < sqrt(n)) {
sort(c.begin() + z * z, c.end());
b[z].resize(n - z * z);
for (__typeof((n)) j = (z * z); j < (n); j += 1) {
b[z][j - z * z] = c[j];
}
d[z] = make_pair(z * z, n);
} else {
b.resize(z);
d.resize(z);
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--, r--, x--;
int less = x - l + 1;
if (r - l <= 2 * z) {
for (__typeof((r + 1)) i = (l); i < (r + 1); i += 1) {
if (a[i] <= a[x]) {
less--;
}
}
if (less == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
continue;
}
int partial_segment1 = -1, partial_segment2 = -1;
for (__typeof((b.size())) i = (0); i < (b.size()); i += 1) {
if (l <= d[i].first && r >= d[i].second) {
less -=
(int)(upper_bound(b[i].begin(), b[i].end(), a[x]) - b[i].begin());
} else if (d[i].first < l && d[i].second > l) {
for (__typeof((d[i].second)) j = (l); j < (d[i].second); j += 1) {
if (a[j] <= a[x]) {
less--;
}
}
} else if (r >= d[i].first && r < d[i].second) {
partial_segment2 = i;
for (__typeof((r + 1)) j = (d[i].first); j < (r + 1); j += 1) {
if (a[j] <= a[x]) {
less--;
}
}
}
}
if (less == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> a, c;
int main() {
int n, m;
cin >> n >> m;
a.resize(n);
for (__typeof((n)) i = (0); i < (n); i += 1) {
cin >> a[i];
}
c = a;
int z = sqrt(n);
vector<vector<int> > b(z + 1);
vector<pair<int, int> > d(z + 1);
for (__typeof((z)) i = (0); i < (z); i += 1) {
sort(c.begin() + i * z, c.begin() + (i + 1) * z);
b[i].resize(z);
for (__typeof(((i + 1) * z)) j = (i * z); j < ((i + 1) * z); j += 1) {
b[i][j - i * z] = c[j];
}
d[i] = make_pair(i * z, (i + 1) * z);
}
if (z < sqrt(n)) {
sort(c.begin() + z * z, c.end());
b[z].resize(n - z * z);
for (__typeof((n)) j = (z * z); j < (n); j += 1) {
b[z][j - z * z] = c[j];
}
d[z] = make_pair(z * z, n);
} else {
b.resize(z);
d.resize(z);
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--, r--, x--;
int less = x - l + 1;
if (r - l <= 2 * z) {
for (__typeof((r + 1)) i = (l); i < (r + 1); i += 1) {
if (a[i] <= a[x]) {
less--;
}
}
if (less == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
continue;
}
int partial_segment1 = -1, partial_segment2 = -1;
for (__typeof((b.size())) i = (0); i < (b.size()); i += 1) {
if (l <= d[i].first && r >= d[i].second) {
less -=
(int)(upper_bound(b[i].begin(), b[i].end(), a[x]) - b[i].begin());
} else if (d[i].first < l && d[i].second > l) {
for (__typeof((d[i].second)) j = (l); j < (d[i].second); j += 1) {
if (a[j] <= a[x]) {
less--;
}
}
} else if (r >= d[i].first && r < d[i].second) {
partial_segment2 = i;
for (__typeof((r + 1)) j = (d[i].first); j < (r + 1); j += 1) {
if (a[j] <= a[x]) {
less--;
}
}
}
}
if (less == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int num[11000], num1[11000];
int i, j, l, r, x;
int main() {
scanf("%d %d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d", &num[i]);
}
for (i = 1; i <= m; i++) {
scanf("%d%d%d", &l, &r, &x);
int sum = 0;
for (j = l; j <= r; j++) {
if (num[j] > num[x]) sum++;
}
if (sum == (r - x))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
int num[11000], num1[11000];
int i, j, l, r, x;
int main() {
scanf("%d %d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d", &num[i]);
}
for (i = 1; i <= m; i++) {
scanf("%d%d%d", &l, &r, &x);
int sum = 0;
for (j = l; j <= r; j++) {
if (num[j] > num[x]) sum++;
}
if (sum == (r - x))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 10100;
int n, m, a[N], l, r, x;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &l, &r, &x);
int cnt = 0;
for (int j = l; j <= r; j++)
if (a[j] < a[x]) cnt++;
puts(cnt == x - l ? "Yes" : "No");
}
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 10100;
int n, m, a[N], l, r, x;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &l, &r, &x);
int cnt = 0;
for (int j = l; j <= r; j++)
if (a[j] < a[x]) cnt++;
puts(cnt == x - l ? "Yes" : "No");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
long long l, r, x;
while (m--) {
cin >> l >> r >> x;
l--;
r--;
x--;
int c = 0;
for (long long i = l; i <= r; i++) {
if (a[i] < a[x]) c++;
}
for (long long i = 0; i < n; i++) {
if (a[i] == a[x] && (x > r || x < l)) {
cout << "Yes" << endl;
} else {
if (a[i] == a[x]) {
if ((i - l) == c)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
}
}
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
long long l, r, x;
while (m--) {
cin >> l >> r >> x;
l--;
r--;
x--;
int c = 0;
for (long long i = l; i <= r; i++) {
if (a[i] < a[x]) c++;
}
for (long long i = 0; i < n; i++) {
if (a[i] == a[x] && (x > r || x < l)) {
cout << "Yes" << endl;
} else {
if (a[i] == a[x]) {
if ((i - l) == c)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long long a1, b, c, i, j, k;
vector<pair<int, int> > v;
pair<int, int> a;
for (i = 0; i < n; i++) {
cin >> a.first;
a.second = i;
v.push_back(a);
}
sort(v.begin(), v.end());
int t[n + 1];
for (i = 0; i < n; i++) {
t[v[i].second] = i;
}
for (i = 0; i < m; i++) {
cin >> a1 >> b >> c;
a1--;
b--;
c--;
k = t[c];
for (j = a1; j <= b; j++) {
if (t[j] < k) a1++;
}
if (a1 == c)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long long a1, b, c, i, j, k;
vector<pair<int, int> > v;
pair<int, int> a;
for (i = 0; i < n; i++) {
cin >> a.first;
a.second = i;
v.push_back(a);
}
sort(v.begin(), v.end());
int t[n + 1];
for (i = 0; i < n; i++) {
t[v[i].second] = i;
}
for (i = 0; i < m; i++) {
cin >> a1 >> b >> c;
a1--;
b--;
c--;
k = t[c];
for (j = a1; j <= b; j++) {
if (t[j] < k) a1++;
}
if (a1 == c)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, q;
cin >> n >> q;
int a[n + 1], l, r, x;
for (int i = 1; i <= n; i++) cin >> a[i];
while (q--) {
int count = 0;
cin >> l >> r >> x;
for (int i = l; i <= r; i++) {
if (a[i] < a[x]) count++;
}
if (a[count + l] == a[x])
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, q;
cin >> n >> q;
int a[n + 1], l, r, x;
for (int i = 1; i <= n; i++) cin >> a[i];
while (q--) {
int count = 0;
cin >> l >> r >> x;
for (int i = l; i <= r; i++) {
if (a[i] < a[x]) count++;
}
if (a[count + l] == a[x])
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
int cur = a[x];
int count = 0;
for (int i = l; i <= r; i++) {
if (a[i] < cur) count++;
}
if (count != x - l)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
int cur = a[x];
int count = 0;
for (int i = l; i <= r; i++) {
if (a[i] < cur) count++;
}
if (count != x - l)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
struct yo {
int val, index;
};
int compare(yo a, yo b) { return a.val < b.val; }
int main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
struct yo a[n];
int b[n];
for (int i = 0; i < n; i++) {
cin >> a[i].val;
a[i].index = i;
b[i] = a[i].val;
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
if (x > r || x < l) {
cout << "Yes\n";
continue;
}
l--;
r--;
x--;
int c = 0;
for (int i = l; i <= r; i++) {
if (i == x) continue;
if (b[i] < b[x]) c++;
}
if (x == l + c)
cout << "Yes\n";
else
cout << "No\n";
}
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct yo {
int val, index;
};
int compare(yo a, yo b) { return a.val < b.val; }
int main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
struct yo a[n];
int b[n];
for (int i = 0; i < n; i++) {
cin >> a[i].val;
a[i].index = i;
b[i] = a[i].val;
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
if (x > r || x < l) {
cout << "Yes\n";
continue;
}
l--;
r--;
x--;
int c = 0;
for (int i = l; i <= r; i++) {
if (i == x) continue;
if (b[i] < b[x]) c++;
}
if (x == l + c)
cout << "Yes\n";
else
cout << "No\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 5;
int a[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
while (m--) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int cnt1 = 0, cnt2 = 0;
for (int i = l; i <= r; i++) {
if (a[i] < a[x]) cnt1++;
if (a[i] == a[x]) cnt2++;
}
if (cnt1 + l - 1 < x && cnt2 + cnt1 + l - 1 >= x)
puts("Yes");
else
puts("No");
}
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 5;
int a[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
while (m--) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int cnt1 = 0, cnt2 = 0;
for (int i = l; i <= r; i++) {
if (a[i] < a[x]) cnt1++;
if (a[i] == a[x]) cnt2++;
}
if (cnt1 + l - 1 < x && cnt2 + cnt1 + l - 1 >= x)
puts("Yes");
else
puts("No");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[10010];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= m; i++) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int xx = 0;
for (int j = l; j <= r; j++) {
if (a[j] < a[x]) {
xx++;
}
}
if (xx != x - l) {
printf("No\n");
} else {
printf("Yes\n");
}
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10010];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= m; i++) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int xx = 0;
for (int j = l; j <= r; j++) {
if (a[j] < a[x]) {
xx++;
}
}
if (xx != x - l) {
printf("No\n");
} else {
printf("Yes\n");
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, m;
while (cin >> n >> m) {
int a[10001];
for (int i = 0; i < n; i++) cin >> a[i];
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
int cur = a[x];
int cnt = 0;
for (int i = l; i <= r; i++) {
if (a[i] < cur) cnt++;
}
if (cnt != x - l)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, m;
while (cin >> n >> m) {
int a[10001];
for (int i = 0; i < n; i++) cin >> a[i];
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
int cur = a[x];
int cnt = 0;
for (int i = l; i <= r; i++) {
if (a[i] < cur) cnt++;
}
if (cnt != x - l)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[10010];
int b[10010];
int main() {
int n, m;
int i, j;
int x, y, z, total, zz;
while (cin >> n >> m) {
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (i = 1; i <= m; i++) {
cin >> x >> y >> z;
total = 0;
if (z > y || z < x) {
cout << "Yes" << endl;
} else {
for (j = x; j <= y; j++) {
if (a[z] > a[j]) total++;
}
zz = x + total;
if (zz == z)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
}
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10010];
int b[10010];
int main() {
int n, m;
int i, j;
int x, y, z, total, zz;
while (cin >> n >> m) {
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (i = 1; i <= m; i++) {
cin >> x >> y >> z;
total = 0;
if (z > y || z < x) {
cout << "Yes" << endl;
} else {
for (j = x; j <= y; j++) {
if (a[z] > a[j]) total++;
}
zz = x + total;
if (zz == z)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, l, r, ind, cnt;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
while (m--) {
cnt = 0;
cin >> l >> r >> ind;
for (int i = l - 1; i < r; i++)
if (a[i] < a[ind - 1]) cnt++;
if (l + cnt == ind)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, l, r, ind, cnt;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
while (m--) {
cnt = 0;
cin >> l >> r >> ind;
for (int i = l - 1; i < r; i++)
if (a[i] < a[ind - 1]) cnt++;
if (l + cnt == ind)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int arr[maxn];
int da[maxn];
int xiao[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
}
while (m--) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int cnt1 = 0, cnt2 = 0;
for (int i = l; i < x; i++) {
if (arr[x] < arr[i]) cnt1++;
}
for (int i = r; i > x; i--) {
if (arr[x] > arr[i]) cnt2++;
}
if (cnt1 != cnt2)
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int arr[maxn];
int da[maxn];
int xiao[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
}
while (m--) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int cnt1 = 0, cnt2 = 0;
for (int i = l; i < x; i++) {
if (arr[x] < arr[i]) cnt1++;
}
for (int i = r; i > x; i--) {
if (arr[x] > arr[i]) cnt2++;
}
if (cnt1 != cnt2)
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
int arr[maxn];
int findsorted(int l, int r, int x, int n) {
int litter = 0;
int e = -1;
for (int i = l; i <= r; i++) {
if (arr[i] < n) {
litter++;
} else if (arr[i] == n) {
e++;
}
}
if (x >= litter && x <= litter + e) return 1;
return 0;
}
int main() {
int n, m;
while (~scanf("%d%d", &n, &m)) {
for (int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
}
for (int i = 1; i <= m; i++) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
if (findsorted(l, r, x - l, arr[x])) {
printf("Yes\n");
} else {
printf("No\n");
}
}
}
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
int arr[maxn];
int findsorted(int l, int r, int x, int n) {
int litter = 0;
int e = -1;
for (int i = l; i <= r; i++) {
if (arr[i] < n) {
litter++;
} else if (arr[i] == n) {
e++;
}
}
if (x >= litter && x <= litter + e) return 1;
return 0;
}
int main() {
int n, m;
while (~scanf("%d%d", &n, &m)) {
for (int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
}
for (int i = 1; i <= m; i++) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
if (findsorted(l, r, x - l, arr[x])) {
printf("Yes\n");
} else {
printf("No\n");
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int p[10005];
int main() {
long long n, m, a, b, c, k;
cin >> n >> m;
for (int i = 0; i < n; i++) scanf("%d", &p[i]);
;
for (int i = 0; i < m; i++) {
scanf("%lld %lld %lld", &a, &b, &c);
;
k = 0;
for (int i = a - 1; i < b; i++)
if (p[i] < p[c - 1]) k++;
if (k == c - a)
printf("Yes\n");
else
printf("No\n");
}
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int p[10005];
int main() {
long long n, m, a, b, c, k;
cin >> n >> m;
for (int i = 0; i < n; i++) scanf("%d", &p[i]);
;
for (int i = 0; i < m; i++) {
scanf("%lld %lld %lld", &a, &b, &c);
;
k = 0;
for (int i = a - 1; i < b; i++)
if (p[i] < p[c - 1]) k++;
if (k == c - a)
printf("Yes\n");
else
printf("No\n");
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long ans, a, b, p[10001], por[10001];
vector<long long> v;
int main() {
cin >> a >> b;
for (int i = 1; i <= a; i++) {
cin >> p[i];
}
for (int i = 1; i <= b; i++) {
int l, r, x;
int cnt = 0;
cin >> l >> r >> x;
for (int j = l; j <= r; j++) {
if (p[j] <= p[x]) {
cnt++;
}
}
if (cnt == x - l + 1) {
cout << "Yes" << '\n';
} else {
cout << "No" << '\n';
}
}
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long ans, a, b, p[10001], por[10001];
vector<long long> v;
int main() {
cin >> a >> b;
for (int i = 1; i <= a; i++) {
cin >> p[i];
}
for (int i = 1; i <= b; i++) {
int l, r, x;
int cnt = 0;
cin >> l >> r >> x;
for (int j = l; j <= r; j++) {
if (p[j] <= p[x]) {
cnt++;
}
}
if (cnt == x - l + 1) {
cout << "Yes" << '\n';
} else {
cout << "No" << '\n';
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10100;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const double dif = 1e-5;
int n, p;
int a[maxn], b[maxn];
bool check(double x) {
double sum = 0;
for (int i = 0; i < n; i++) sum += max(0.0, a[i] * x - b[i]);
if (sum < x * p)
return true;
else
return false;
}
int main(void) {
int n, m;
while (cin >> n >> m) {
for (int i = 1; i <= n; i++) cin >> a[i];
while (m--) {
int l, r, x, cnt = 0;
cin >> l >> r >> x;
for (int i = l; i <= r; i++)
if (a[i] < a[x]) cnt++;
if (cnt == x - l)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10100;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const double dif = 1e-5;
int n, p;
int a[maxn], b[maxn];
bool check(double x) {
double sum = 0;
for (int i = 0; i < n; i++) sum += max(0.0, a[i] * x - b[i]);
if (sum < x * p)
return true;
else
return false;
}
int main(void) {
int n, m;
while (cin >> n >> m) {
for (int i = 1; i <= n; i++) cin >> a[i];
while (m--) {
int l, r, x, cnt = 0;
cin >> l >> r >> x;
for (int i = l; i <= r; i++)
if (a[i] < a[x]) cnt++;
if (cnt == x - l)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int main() {
int n, m, p[10009];
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> p[i];
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
if (c < a || c > b) {
cout << "Yes\n";
continue;
}
int tmp = c - a, cnt = 0;
for (int j = a; j <= b; j++)
if (p[j] < p[c]) cnt++;
if (cnt == tmp)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int main() {
int n, m, p[10009];
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> p[i];
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
if (c < a || c > b) {
cout << "Yes\n";
continue;
}
int tmp = c - a, cnt = 0;
for (int j = a; j <= b; j++)
if (p[j] < p[c]) cnt++;
if (cnt == tmp)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int partition(int arr[], int l, int r) {
int x = arr[r], i = l;
for (int j = l; j <= r - 1; j++) {
if (arr[j] <= x) {
swap(&arr[i], &arr[j]);
i++;
}
}
swap(&arr[i], &arr[r]);
return i;
}
int randomPartition(int arr[], int l, int r) {
int n = r - l + 1;
int pivot = rand() % n;
swap(&arr[l + pivot], &arr[r]);
return partition(arr, l, r);
}
int kthSmallest(int arr[], int l, int r, int k) {
if (k > 0 && k <= r - l + 1) {
int pos = randomPartition(arr, l, r);
if (pos - l == k - 1) return arr[pos];
if (pos - l > k - 1) return kthSmallest(arr, l, pos - 1, k);
return kthSmallest(arr, pos + 1, r, k - pos + l - 1);
}
return INT_MAX;
}
int main() {
int n, m, l, r, x;
cin >> n >> m;
int a[n], temp[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
temp[i] = a[i];
}
while (m--) {
cin >> l >> r >> x;
if (kthSmallest(temp, l - 1, r - 1, x - l + 1) == a[x - 1]) {
cout << "Yes\n";
} else {
cout << "No\n";
}
for (int i = 0; i < n; i++) temp[i] = a[i];
}
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int partition(int arr[], int l, int r) {
int x = arr[r], i = l;
for (int j = l; j <= r - 1; j++) {
if (arr[j] <= x) {
swap(&arr[i], &arr[j]);
i++;
}
}
swap(&arr[i], &arr[r]);
return i;
}
int randomPartition(int arr[], int l, int r) {
int n = r - l + 1;
int pivot = rand() % n;
swap(&arr[l + pivot], &arr[r]);
return partition(arr, l, r);
}
int kthSmallest(int arr[], int l, int r, int k) {
if (k > 0 && k <= r - l + 1) {
int pos = randomPartition(arr, l, r);
if (pos - l == k - 1) return arr[pos];
if (pos - l > k - 1) return kthSmallest(arr, l, pos - 1, k);
return kthSmallest(arr, pos + 1, r, k - pos + l - 1);
}
return INT_MAX;
}
int main() {
int n, m, l, r, x;
cin >> n >> m;
int a[n], temp[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
temp[i] = a[i];
}
while (m--) {
cin >> l >> r >> x;
if (kthSmallest(temp, l - 1, r - 1, x - l + 1) == a[x - 1]) {
cout << "Yes\n";
} else {
cout << "No\n";
}
for (int i = 0; i < n; i++) temp[i] = a[i];
}
return 0;
}
``` |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
int mox[8] = {1, 0, 0, -1, 1, -1, 1, -1};
int moy[8] = {0, -1, 1, 0, -1, -1, 1, 1};
char mover[4] = {'D', 'L', 'R', 'U'};
const long long INF = 1LL << 61;
const int inf = 2e9;
const long double PI = acos(-1.0);
const long double EPS = 1e-9;
bool debug;
using namespace std;
void solve();
int main() {
debug = 0;
cout.precision(30);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand((unsigned)time(NULL));
solve();
if (debug)
cout << '\n'
<< '\n'
<< "time: " << clock() * 1.0 / CLOCKS_PER_SEC * 1000 << " ms" << '\n';
}
const int N = 200005;
const int MAGIC = 420;
const int lg = 26;
void solve() {
int n, m, l, r, pos;
cin >> n >> m;
vector<int> a(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> a[i];
while (m--) {
cin >> l >> r >> pos;
int cnt = 0;
for (int i = l; i <= r; i++)
if (a[i] <= a[pos]) cnt++;
int RealPos = pos - l + 1;
if (RealPos == cnt)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
}
| ### Prompt
In CPP, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
int mox[8] = {1, 0, 0, -1, 1, -1, 1, -1};
int moy[8] = {0, -1, 1, 0, -1, -1, 1, 1};
char mover[4] = {'D', 'L', 'R', 'U'};
const long long INF = 1LL << 61;
const int inf = 2e9;
const long double PI = acos(-1.0);
const long double EPS = 1e-9;
bool debug;
using namespace std;
void solve();
int main() {
debug = 0;
cout.precision(30);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand((unsigned)time(NULL));
solve();
if (debug)
cout << '\n'
<< '\n'
<< "time: " << clock() * 1.0 / CLOCKS_PER_SEC * 1000 << " ms" << '\n';
}
const int N = 200005;
const int MAGIC = 420;
const int lg = 26;
void solve() {
int n, m, l, r, pos;
cin >> n >> m;
vector<int> a(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> a[i];
while (m--) {
cin >> l >> r >> pos;
int cnt = 0;
for (int i = l; i <= r; i++)
if (a[i] <= a[pos]) cnt++;
int RealPos = pos - l + 1;
if (RealPos == cnt)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 10;
vector<int> tree[maxn << 2];
int arr[maxn];
void build(int node, int l, int r) {
if (l == r) {
tree[node].push_back(arr[l]);
return;
}
int mid = l + r >> 1;
build(node << 1, l, mid);
build(node << 1 | 1, mid + 1, r);
merge(tree[node << 1].begin(), tree[node << 1].end(),
tree[node << 1 | 1].begin(), tree[node << 1 | 1].end(),
back_inserter(tree[node]));
}
int query(int node, int l, int r, int i, int j, int k) {
if (r < i || l > j) return 0;
if (i <= l && r <= j) {
return lower_bound(tree[node].begin(), tree[node].end(), k) -
tree[node].begin();
}
int mid = l + r >> 1;
return query(node << 1, l, mid, i, j, k) +
query(node << 1 | 1, mid + 1, r, i, j, k);
}
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> arr[i];
build(1, 0, n - 1);
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--, r--, x--;
int cnt = query(1, 0, n - 1, l, r, arr[x]);
if (cnt == (x - l))
cout << "Yes\n";
else
cout << "No\n";
}
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 10;
vector<int> tree[maxn << 2];
int arr[maxn];
void build(int node, int l, int r) {
if (l == r) {
tree[node].push_back(arr[l]);
return;
}
int mid = l + r >> 1;
build(node << 1, l, mid);
build(node << 1 | 1, mid + 1, r);
merge(tree[node << 1].begin(), tree[node << 1].end(),
tree[node << 1 | 1].begin(), tree[node << 1 | 1].end(),
back_inserter(tree[node]));
}
int query(int node, int l, int r, int i, int j, int k) {
if (r < i || l > j) return 0;
if (i <= l && r <= j) {
return lower_bound(tree[node].begin(), tree[node].end(), k) -
tree[node].begin();
}
int mid = l + r >> 1;
return query(node << 1, l, mid, i, j, k) +
query(node << 1 | 1, mid + 1, r, i, j, k);
}
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> arr[i];
build(1, 0, n - 1);
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--, r--, x--;
int cnt = query(1, 0, n - 1, l, r, arr[x]);
if (cnt == (x - l))
cout << "Yes\n";
else
cout << "No\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
vector<int> P;
int main() {
int n, m;
scanf("%d %d", &n, &m);
P.resize(n);
for (int i = 0; i < n; i++) {
scanf("%d", &P[i]);
}
for (int i = 0; i < m; i++) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
l--, r--, x--;
int xx = l;
for (int e = l; e <= r; e++) {
if (P[e] < P[x]) xx++;
if (xx > x) break;
}
if (xx != x)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> P;
int main() {
int n, m;
scanf("%d %d", &n, &m);
P.resize(n);
for (int i = 0; i < n; i++) {
scanf("%d", &P[i]);
}
for (int i = 0; i < m; i++) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
l--, r--, x--;
int xx = l;
for (int e = l; e <= r; e++) {
if (P[e] < P[x]) xx++;
if (xx > x) break;
}
if (xx != x)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[12345];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) {
int l, r, x, tt = 0;
cin >> l >> r >> x;
l--, r--, x--;
for (int j = l; j <= r; j++)
if (a[j] < a[x]) tt++;
if (x == l + tt)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, a[12345];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) {
int l, r, x, tt = 0;
cin >> l >> r >> x;
l--, r--, x--;
for (int j = l; j <= r; j++)
if (a[j] < a[x]) tt++;
if (x == l + tt)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[10001];
bool b[10001] = {};
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
int l, r;
cin >> l >> r;
fill(b, b + 10000, 0);
for (int j = l; j <= r; j++) {
b[a[j]] = true;
}
int count = 0;
int x;
cin >> x;
for (int j = 1; j <= a[x]; j++) {
if (b[j]) {
count++;
}
}
x = x - l + 1;
if (x == count) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
| ### Prompt
Generate a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10001];
bool b[10001] = {};
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
int l, r;
cin >> l >> r;
fill(b, b + 10000, 0);
for (int j = l; j <= r; j++) {
b[a[j]] = true;
}
int count = 0;
int x;
cin >> x;
for (int j = 1; j <= a[x]; j++) {
if (b[j]) {
count++;
}
}
x = x - l + 1;
if (x == count) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int n, m, l_i, r_i, x_i;
scanf("%d %d", &n, &m);
int permutation[n];
for (int i = 0; i < n; i++) {
scanf("%d", &permutation[i]);
}
for (int i = 0; i < m; i++) {
scanf("%d %d %d", &l_i, &r_i, &x_i);
l_i--;
r_i--;
x_i--;
int counter = 0;
for (int j = l_i; j <= r_i; j++) {
if (permutation[j] < permutation[x_i]) {
counter++;
}
}
if (counter == (x_i - l_i) || (x_i < l_i) || (x_i > r_i))
printf("Yes\n");
else
printf("No\n");
}
}
| ### Prompt
Please create a solution in CPP to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int n, m, l_i, r_i, x_i;
scanf("%d %d", &n, &m);
int permutation[n];
for (int i = 0; i < n; i++) {
scanf("%d", &permutation[i]);
}
for (int i = 0; i < m; i++) {
scanf("%d %d %d", &l_i, &r_i, &x_i);
l_i--;
r_i--;
x_i--;
int counter = 0;
for (int j = l_i; j <= r_i; j++) {
if (permutation[j] < permutation[x_i]) {
counter++;
}
}
if (counter == (x_i - l_i) || (x_i < l_i) || (x_i > r_i))
printf("Yes\n");
else
printf("No\n");
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> nums(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> nums[i];
while (m-- > 0) {
int l, r, x;
cin >> l >> r >> x;
int a = x - l;
int b = 0;
for (int i = l; i <= r; i++)
if (nums[i] < nums[x]) b++;
if (a != b)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> nums(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> nums[i];
while (m-- > 0) {
int l, r, x;
cin >> l >> r >> x;
int a = x - l;
int b = 0;
for (int i = l; i <= r; i++)
if (nums[i] < nums[x]) b++;
if (a != b)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const int MOD = 1000000007;
int a[300005];
int main() {
int n, p;
cin >> n >> p;
for (int i = 1; i <= n; i++) cin >> a[i];
while (p--) {
int l, r, x;
cin >> l >> r >> x;
int lar = r - x;
int num = a[x];
int count = 0;
for (int i = l; i <= r; i++) {
if (a[i] > num) {
count++;
}
}
if (count == lar) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const int MOD = 1000000007;
int a[300005];
int main() {
int n, p;
cin >> n >> p;
for (int i = 1; i <= n; i++) cin >> a[i];
while (p--) {
int l, r, x;
cin >> l >> r >> x;
int lar = r - x;
int num = a[x];
int count = 0;
for (int i = l; i <= r; i++) {
if (a[i] > num) {
count++;
}
}
if (count == lar) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return a * (b / gcd(a, b));
}
int dr[] = {+1, -1, +0, +0};
int dc[] = {+0, +0, +1, -1};
int X[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int Y[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int KX[] = {-2, -2, -1, -1, 1, 1, 2, 2};
int KY[] = {-1, 1, -2, 2, -2, 2, -1, 1};
int main() {
int n, m;
cin >> n >> m;
int a[n + 5];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
int cnt = 0;
for (int j = l; j <= r; j++) {
cnt += a[j] < a[x];
}
if (l + cnt == x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
| ### Prompt
Develop a solution in cpp to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return a * (b / gcd(a, b));
}
int dr[] = {+1, -1, +0, +0};
int dc[] = {+0, +0, +1, -1};
int X[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int Y[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int KX[] = {-2, -2, -1, -1, 1, 1, 2, 2};
int KY[] = {-1, 1, -2, 2, -2, 2, -1, 1};
int main() {
int n, m;
cin >> n >> m;
int a[n + 5];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
int cnt = 0;
for (int j = l; j <= r; j++) {
cnt += a[j] < a[x];
}
if (l + cnt == x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double EPS = 1e-9;
const int INF = 1 << 29;
int const NN = 1e4 + 4;
int p[NN];
int main() {
int n, m;
scanf("%d", &n);
scanf("%d", &m);
for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
while (m--) {
int l, r, x;
scanf("%d", &l);
scanf("%d", &r);
scanf("%d", &x);
int cnt = 0;
for (int i = l; i <= r; ++i) {
if (i == x) continue;
if (p[i] < p[x]) ++cnt;
}
if (cnt + l == x) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double EPS = 1e-9;
const int INF = 1 << 29;
int const NN = 1e4 + 4;
int p[NN];
int main() {
int n, m;
scanf("%d", &n);
scanf("%d", &m);
for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
while (m--) {
int l, r, x;
scanf("%d", &l);
scanf("%d", &r);
scanf("%d", &x);
int cnt = 0;
for (int i = l; i <= r; ++i) {
if (i == x) continue;
if (p[i] < p[x]) ++cnt;
}
if (cnt + l == x) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void prll(vector<T> s) {
for (long long i = 0; i < s.size(); i++) cout << s[i] << " ";
cout << endl;
}
template <class T>
void prll(vector<pair<T, T> > s) {
for (long long i = 0; i < s.size(); i++)
cout << s[i].first + 1 << " " << s[i].second + 1 << endl;
;
cout << endl;
}
template <class T>
void prll(vector<vector<T> > s) {
for (long long i = 0; i < s.size(); i++) prll(s[i]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
srand(time(NULL));
int n, m;
cin >> n >> m;
vector<int> s(n);
vector<int> lst(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
s[i]--;
lst[s[i]] = i;
}
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
if (x < l || x > r) {
cout << "Yes" << endl;
continue;
}
int cnt = 0;
for (int j = l; j <= r; j++) {
if (s[j] < s[x]) cnt++;
}
if (x == l + cnt)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
void prll(vector<T> s) {
for (long long i = 0; i < s.size(); i++) cout << s[i] << " ";
cout << endl;
}
template <class T>
void prll(vector<pair<T, T> > s) {
for (long long i = 0; i < s.size(); i++)
cout << s[i].first + 1 << " " << s[i].second + 1 << endl;
;
cout << endl;
}
template <class T>
void prll(vector<vector<T> > s) {
for (long long i = 0; i < s.size(); i++) prll(s[i]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
srand(time(NULL));
int n, m;
cin >> n >> m;
vector<int> s(n);
vector<int> lst(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
s[i]--;
lst[s[i]] = i;
}
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
if (x < l || x > r) {
cout << "Yes" << endl;
continue;
}
int cnt = 0;
for (int j = l; j <= r; j++) {
if (s[j] < s[x]) cnt++;
}
if (x == l + cnt)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int maxn = 1e9 + 10;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const double PI = acos(-1.0);
const double eps(1e-8);
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> p(n + 1);
for (int i = 1; i <= n; i += 1) cin >> p[i];
while (m--) {
int l, r, x;
cin >> l >> r >> x;
int tmp = 0;
int pos = INF;
for (int i = l; i <= r; i += 1) {
tmp += (p[i] < p[x]);
if (p[i] == p[x]) pos = (i - l);
}
if (pos == INF) {
cout << "No" << endl;
continue;
}
cout << (pos == tmp ? "Yes" : "No") << endl;
}
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int maxn = 1e9 + 10;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const double PI = acos(-1.0);
const double eps(1e-8);
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> p(n + 1);
for (int i = 1; i <= n; i += 1) cin >> p[i];
while (m--) {
int l, r, x;
cin >> l >> r >> x;
int tmp = 0;
int pos = INF;
for (int i = l; i <= r; i += 1) {
tmp += (p[i] < p[x]);
if (p[i] == p[x]) pos = (i - l);
}
if (pos == INF) {
cout << "No" << endl;
continue;
}
cout << (pos == tmp ? "Yes" : "No") << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[10010];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
while (m--) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int c = 0;
int xx = x - l;
for (int i = l; i <= r; i++) {
if (a[i] < a[x]) c++;
if (xx < c) break;
}
if (xx == c)
printf("Yes\n");
else
printf("No\n");
}
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10010];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
while (m--) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int c = 0;
int xx = x - l;
for (int i = l; i <= r; i++) {
if (a[i] < a[x]) c++;
if (xx < c) break;
}
if (xx == c)
printf("Yes\n");
else
printf("No\n");
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, v[10005], esq = 0;
int ini, fim, pg, cont = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = 1; i <= m; i++) {
cont = 0;
cin >> ini >> fim >> pg;
esq = abs(pg - ini);
for (int j = ini; j <= fim; j++) {
if (v[pg] > v[j]) cont++;
}
if (esq == cont)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, v[10005], esq = 0;
int ini, fim, pg, cont = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = 1; i <= m; i++) {
cont = 0;
cin >> ini >> fim >> pg;
esq = abs(pg - ini);
for (int j = ini; j <= fim; j++) {
if (v[pg] > v[j]) cont++;
}
if (esq == cont)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, -1, 0, 1, -1, -1, 1};
const int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1};
const int N = 0;
const int MOD = 0;
const int INF = 1e9 + 10;
const long long int LLINF = 1e18 + 10;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int v[10010];
int l, r, x;
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
int aux;
bool mudou;
int cnt = 0;
while (m--) {
cin >> l >> r >> x;
aux = x - l;
cnt = 0;
for (int i = l; i <= r; i++) {
if (v[i] < v[x]) cnt++;
}
if (cnt == aux)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, -1, 0, 1, -1, -1, 1};
const int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1};
const int N = 0;
const int MOD = 0;
const int INF = 1e9 + 10;
const long long int LLINF = 1e18 + 10;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int v[10010];
int l, r, x;
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
int aux;
bool mudou;
int cnt = 0;
while (m--) {
cin >> l >> r >> x;
aux = x - l;
cnt = 0;
for (int i = l; i <= r; i++) {
if (v[i] < v[x]) cnt++;
}
if (cnt == aux)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7f7f7f7f;
template <typename t>
t read() {
t x = 0;
int f = 1;
char c = getchar();
while (c > '9' || c < '0') f = c == '-' ? -1 : 1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
template <typename t>
void write(t x) {
if (x < 0) {
putchar('-'), write(-x);
return;
}
if (x >= 10) write(x / 10);
putchar(x % 10 + 48);
}
struct data {
int id, l, r, x;
bool operator<(const data &t) const { return x < t.x; }
} a[10010];
int n, m, p[10010], sum[10010];
bool ans[10010];
int main() {
n = read<int>(), m = read<int>();
for (int i = 1; i <= n; i++) p[i] = read<int>();
for (int i = 1; i <= m; i++)
a[a[i].id = i].l = read<int>(), a[i].r = read<int>(), a[i].x = read<int>();
sort(a + 1, a + m + 1);
for (int i = 1; i <= m; i++) {
if (a[i].x != a[i - 1].x) {
for (int j = 1; j <= n; j++) sum[j] = 0;
for (int j = 1; j <= n; j++) {
sum[j] = sum[j - 1];
if (p[j] < p[a[i].x]) sum[j]++;
}
}
if (sum[a[i].r] - sum[a[i].l - 1] + 1 == a[i].x - a[i].l + 1)
ans[a[i].id] = 1;
}
for (int i = 1; i <= m; i++) puts(ans[i] ? "Yes" : "No");
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7f7f7f7f;
template <typename t>
t read() {
t x = 0;
int f = 1;
char c = getchar();
while (c > '9' || c < '0') f = c == '-' ? -1 : 1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
template <typename t>
void write(t x) {
if (x < 0) {
putchar('-'), write(-x);
return;
}
if (x >= 10) write(x / 10);
putchar(x % 10 + 48);
}
struct data {
int id, l, r, x;
bool operator<(const data &t) const { return x < t.x; }
} a[10010];
int n, m, p[10010], sum[10010];
bool ans[10010];
int main() {
n = read<int>(), m = read<int>();
for (int i = 1; i <= n; i++) p[i] = read<int>();
for (int i = 1; i <= m; i++)
a[a[i].id = i].l = read<int>(), a[i].r = read<int>(), a[i].x = read<int>();
sort(a + 1, a + m + 1);
for (int i = 1; i <= m; i++) {
if (a[i].x != a[i - 1].x) {
for (int j = 1; j <= n; j++) sum[j] = 0;
for (int j = 1; j <= n; j++) {
sum[j] = sum[j - 1];
if (p[j] < p[a[i].x]) sum[j]++;
}
}
if (sum[a[i].r] - sum[a[i].l - 1] + 1 == a[i].x - a[i].l + 1)
ans[a[i].id] = 1;
}
for (int i = 1; i <= m; i++) puts(ans[i] ? "Yes" : "No");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool checkIfChanges(vector<int> original, int index, int l, int r) {
int countLess = 0;
int target = original[index - 1];
for (auto it = original.begin() + l - 1; it != original.begin() + r; it++) {
if (*it < target) countLess++;
}
return l + countLess == index;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> pages(n);
int page;
for (int i = 0; i < n; i++) {
cin >> page;
pages[i] = page;
}
int l, x, r;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
if (checkIfChanges(pages, x, l, r)) {
cout << "Yes"
<< "\n";
} else
cout << "No"
<< "\n";
}
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool checkIfChanges(vector<int> original, int index, int l, int r) {
int countLess = 0;
int target = original[index - 1];
for (auto it = original.begin() + l - 1; it != original.begin() + r; it++) {
if (*it < target) countLess++;
}
return l + countLess == index;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> pages(n);
int page;
for (int i = 0; i < n; i++) {
cin >> page;
pages[i] = page;
}
int l, x, r;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
if (checkIfChanges(pages, x, l, r)) {
cout << "Yes"
<< "\n";
} else
cout << "No"
<< "\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool vowel(char a) {
a = toupper(a);
if ((a == 'A') || (a == 'E') || (a == 'I') || (a == 'O') || (a == 'U'))
return 1;
return 0;
}
long long int n, m, q, a, b, c, sum = 0, cnt = 0;
long long int arr[500055];
map<long long int, bool> mp;
string str;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> arr[i];
for (int j = 0; j < m; j++) {
cin >> a >> b >> c;
long long int tk = arr[c];
int bg = 0, sm = 0;
for (int i = a; i <= b; i++) {
if (arr[i] > tk) bg++;
}
int pos = b - bg;
if (pos == c) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
}
}
| ### Prompt
Please create a solution in CPP to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool vowel(char a) {
a = toupper(a);
if ((a == 'A') || (a == 'E') || (a == 'I') || (a == 'O') || (a == 'U'))
return 1;
return 0;
}
long long int n, m, q, a, b, c, sum = 0, cnt = 0;
long long int arr[500055];
map<long long int, bool> mp;
string str;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> arr[i];
for (int j = 0; j < m; j++) {
cin >> a >> b >> c;
long long int tk = arr[c];
int bg = 0, sm = 0;
for (int i = a; i <= b; i++) {
if (arr[i] > tk) bg++;
}
int pos = b - bg;
if (pos == c) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int p[n], mom[m][3], arr[n], hsh;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = 0; i < m; i++) {
cin >> mom[i][0];
cin >> mom[i][1];
cin >> mom[i][2];
}
for (int i = 0; i < m; i++) {
int l = mom[i][0] - 1;
int r = mom[i][1] - 1;
int index = mom[i][2];
int cnt = 0;
if (l == r || (index - 1) > r || (index - 1) < l) {
cout << "Yes\n";
continue;
}
for (int j = l; j <= r; j++) {
if (p[j] < p[index - 1]) cnt++;
}
if ((cnt + l + 1) == index)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int p[n], mom[m][3], arr[n], hsh;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = 0; i < m; i++) {
cin >> mom[i][0];
cin >> mom[i][1];
cin >> mom[i][2];
}
for (int i = 0; i < m; i++) {
int l = mom[i][0] - 1;
int r = mom[i][1] - 1;
int index = mom[i][2];
int cnt = 0;
if (l == r || (index - 1) > r || (index - 1) < l) {
cout << "Yes\n";
continue;
}
for (int j = l; j <= r; j++) {
if (p[j] < p[index - 1]) cnt++;
}
if ((cnt + l + 1) == index)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
int ar[n];
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
for (int i = 0; i < m; i++) {
int x, y, z;
cin >> x >> y >> z;
int big = 0, small = 0;
for (int j = x - 1; j < y; j++) {
if (ar[j] > ar[z - 1]) {
big++;
} else if (ar[j] < ar[z - 1]) {
small++;
}
}
if (x + small == z) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
int ar[n];
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
for (int i = 0; i < m; i++) {
int x, y, z;
cin >> x >> y >> z;
int big = 0, small = 0;
for (int j = x - 1; j < y; j++) {
if (ar[j] > ar[z - 1]) {
big++;
} else if (ar[j] < ar[z - 1]) {
small++;
}
}
if (x + small == z) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
const int maxn = 10005;
using namespace std;
int a[maxn], b[maxn];
int main() {
int n, i, m, j, l, r, x;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i <= m; i++) {
scanf("%d%d%d", &l, &r, &x);
int num = 0;
for (j = l; j <= r; j++) {
if (a[j] < a[x]) num++;
}
if (a[l + num] == a[x])
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
const int maxn = 10005;
using namespace std;
int a[maxn], b[maxn];
int main() {
int n, i, m, j, l, r, x;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i <= m; i++) {
scanf("%d%d%d", &l, &r, &x);
int num = 0;
for (j = l; j <= r; j++) {
if (a[j] < a[x]) num++;
}
if (a[l + num] == a[x])
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> nums(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> nums[i];
while (m-- > 0) {
int l, r, x;
cin >> l >> r >> x;
int a = x - l;
int b = 0;
for (int i = l; i <= r; i++)
if (nums[i] < nums[x]) b++;
if (a != b)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
| ### Prompt
In cpp, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> nums(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> nums[i];
while (m-- > 0) {
int l, r, x;
cin >> l >> r >> x;
int a = x - l;
int b = 0;
for (int i = l; i <= r; i++)
if (nums[i] < nums[x]) b++;
if (a != b)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int i, j, k;
struct query {
int l, r, x;
};
void phantom_sort(int *a, int n) {
int maxi = 0;
for (int l = 0; l < n; ++l) maxi = max(maxi, a[l]);
int freq[maxi + 1];
fill(freq, freq + maxi + 1, 0);
for (int l = 0; l < n; ++l) ++freq[a[l]];
int in = 0;
for (int m = 0; m < maxi + 1; ++m) {
while (freq[m]--) a[in++] = m;
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, m;
cin >> n >> m;
int a[n];
for (i = 0; i < n; ++i) cin >> a[i];
query mom;
int *tmp;
for (i = 0; i < m; ++i) {
cin >> mom.l >> mom.r >> mom.x;
tmp = new int[mom.r - mom.l + 1];
k = 0;
for (j = mom.l - 1; j < mom.r; ++j) tmp[k++] = a[j];
phantom_sort(tmp, (mom.r - mom.l + 1));
if (tmp[mom.x - mom.l] == a[mom.x - 1])
cout << "Yes\n";
else
cout << "No\n";
delete tmp;
}
}
| ### Prompt
Develop a solution in cpp to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int i, j, k;
struct query {
int l, r, x;
};
void phantom_sort(int *a, int n) {
int maxi = 0;
for (int l = 0; l < n; ++l) maxi = max(maxi, a[l]);
int freq[maxi + 1];
fill(freq, freq + maxi + 1, 0);
for (int l = 0; l < n; ++l) ++freq[a[l]];
int in = 0;
for (int m = 0; m < maxi + 1; ++m) {
while (freq[m]--) a[in++] = m;
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, m;
cin >> n >> m;
int a[n];
for (i = 0; i < n; ++i) cin >> a[i];
query mom;
int *tmp;
for (i = 0; i < m; ++i) {
cin >> mom.l >> mom.r >> mom.x;
tmp = new int[mom.r - mom.l + 1];
k = 0;
for (j = mom.l - 1; j < mom.r; ++j) tmp[k++] = a[j];
phantom_sort(tmp, (mom.r - mom.l + 1));
if (tmp[mom.x - mom.l] == a[mom.x - 1])
cout << "Yes\n";
else
cout << "No\n";
delete tmp;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007;
const int max_size = 100001;
int parent[max_size];
int Size[max_size];
int root(int x) {
while (x != parent[x]) {
parent[x] = parent[parent[x]];
x = parent[x];
}
return x;
}
void sunion(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx != ry) {
if (Size[rx] > Size[ry]) {
parent[ry] = parent[rx];
Size[rx] += Size[ry];
} else {
parent[rx] = parent[ry];
Size[ry] += Size[rx];
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
int n, m;
cin >> n >> m;
int p[n + 1];
for (int i = 1; i <= n; i++) cin >> p[i];
int l, r, x;
while (m--) {
cin >> l >> r >> x;
int v = p[x];
int cl = 0;
for (int i = l; i <= r; i++) {
if (p[i] < v) cl++;
}
if (l + cl != x)
cout << "No\n";
else
cout << "Yes\n";
}
}
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007;
const int max_size = 100001;
int parent[max_size];
int Size[max_size];
int root(int x) {
while (x != parent[x]) {
parent[x] = parent[parent[x]];
x = parent[x];
}
return x;
}
void sunion(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx != ry) {
if (Size[rx] > Size[ry]) {
parent[ry] = parent[rx];
Size[rx] += Size[ry];
} else {
parent[rx] = parent[ry];
Size[ry] += Size[rx];
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
int n, m;
cin >> n >> m;
int p[n + 1];
for (int i = 1; i <= n; i++) cin >> p[i];
int l, r, x;
while (m--) {
cin >> l >> r >> x;
int v = p[x];
int cl = 0;
for (int i = l; i <= r; i++) {
if (p[i] < v) cl++;
}
if (l + cl != x)
cout << "No\n";
else
cout << "Yes\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int temp;
int l, r, x;
vec.push_back(0);
for (int i = 0; i < n; i++) {
cin >> temp;
vec.push_back(temp);
}
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
int kol = 0;
for (int j = l; j <= r; j++) {
if (vec[j] < vec[x]) kol++;
}
if (kol == x - l) {
cout << "Yes";
} else {
cout << "No";
}
cout << endl;
}
return 0;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int temp;
int l, r, x;
vec.push_back(0);
for (int i = 0; i < n; i++) {
cin >> temp;
vec.push_back(temp);
}
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
int kol = 0;
for (int j = l; j <= r; j++) {
if (vec[j] < vec[x]) kol++;
}
if (kol == x - l) {
cout << "Yes";
} else {
cout << "No";
}
cout << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int A[10003];
int N, M;
vector<int> t[100000];
int found;
vector<int> init(int l, int r, int node) {
if (l == r) return t[node] = vector<int>({A[l]});
int mid = (l + r) / 2;
vector<int> L = init(l, mid, 2 * node);
vector<int> R = init(mid + 1, r, 2 * node + 1);
vector<int> ret;
int posl = 0;
int posr = 0;
while (posl < L.size() && posr < R.size()) {
if (L[posl] < R[posr])
ret.push_back(L[posl++]);
else
ret.push_back(R[posr++]);
}
for (; posl < L.size(); posl++) ret.push_back(L[posl]);
for (; posr < R.size(); posr++) ret.push_back(R[posr]);
return t[node] = ret;
}
int query(int nl, int nr, int l, int r, int node, int num) {
if (l <= nl && nr <= r) {
if (t[node][lower_bound(t[node].begin(), t[node].end(), num) -
t[node].begin()] == num)
found = 1;
return lower_bound(t[node].begin(), t[node].end(), num) - t[node].begin();
}
if (r < nl || nr < l) return 0;
int nm = (nl + nr) / 2;
return query(nl, nm, l, r, 2 * node, num) +
query(nm + 1, nr, l, r, 2 * node + 1, num);
}
int main() {
cin >> N >> M;
for (int i = 0; i < N; i++) cin >> A[i];
init(0, N - 1, 1);
for (int i = 0; i < M; i++) {
int l, r, x;
cin >> l >> r >> x;
found = 0;
int smaller = query(0, N - 1, l - 1, r - 1, 1, A[x - 1]);
if (!found)
cout << "Yes\n";
else {
if (smaller == x - l)
cout << "Yes\n";
else
cout << "No\n";
}
}
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int A[10003];
int N, M;
vector<int> t[100000];
int found;
vector<int> init(int l, int r, int node) {
if (l == r) return t[node] = vector<int>({A[l]});
int mid = (l + r) / 2;
vector<int> L = init(l, mid, 2 * node);
vector<int> R = init(mid + 1, r, 2 * node + 1);
vector<int> ret;
int posl = 0;
int posr = 0;
while (posl < L.size() && posr < R.size()) {
if (L[posl] < R[posr])
ret.push_back(L[posl++]);
else
ret.push_back(R[posr++]);
}
for (; posl < L.size(); posl++) ret.push_back(L[posl]);
for (; posr < R.size(); posr++) ret.push_back(R[posr]);
return t[node] = ret;
}
int query(int nl, int nr, int l, int r, int node, int num) {
if (l <= nl && nr <= r) {
if (t[node][lower_bound(t[node].begin(), t[node].end(), num) -
t[node].begin()] == num)
found = 1;
return lower_bound(t[node].begin(), t[node].end(), num) - t[node].begin();
}
if (r < nl || nr < l) return 0;
int nm = (nl + nr) / 2;
return query(nl, nm, l, r, 2 * node, num) +
query(nm + 1, nr, l, r, 2 * node + 1, num);
}
int main() {
cin >> N >> M;
for (int i = 0; i < N; i++) cin >> A[i];
init(0, N - 1, 1);
for (int i = 0; i < M; i++) {
int l, r, x;
cin >> l >> r >> x;
found = 0;
int smaller = query(0, N - 1, l - 1, r - 1, 1, A[x - 1]);
if (!found)
cout << "Yes\n";
else {
if (smaller == x - l)
cout << "Yes\n";
else
cout << "No\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long hcf(long long a, long long b) {
if (b == 0) return a;
return hcf(b, a % b);
}
long long stringtoll(string s) {
long long ans = 0;
for (int i = 0; i < s.length(); i++) ans = ans * 10 + (s[i] - '0');
return ans;
}
vector<long long> allroot(long long n) {
vector<long long> ans;
for (long long i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
ans.push_back(i);
if (i != n / i) ans.push_back(n / i);
}
}
return ans;
}
bool prime(long long n) {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) return false;
}
return true;
}
long long logi(long long n, long long base) { return (log(n) / log(base)); }
long long mulmod(long long a, long long b, long long c) {
if (b == 0) return 0;
long long s = mulmod(a, b / 2, c);
if (b % 2 == 1)
return (a % c + 2 * (s % c)) % c;
else
return (2 * (s % c)) % c;
}
long long factorial(long long n) {
if (n == 0) return 1;
return (n * factorial(n - 1)) % 1000000007;
}
bool right(long long val, long long l, long long r) {
if (val >= l && val <= r) return true;
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, m;
cin >> n >> m;
long long p[n];
for (long long i = 0; i < n; i++) cin >> p[i];
int b = 0;
int c = 0;
for (int i = 0; i < m; i++) {
int b = 0;
int c = 0;
int l, r, x;
cin >> l >> r >> x;
for (int j = l - 1; j < r; j++) {
if (p[x - 1] > p[j]) {
b = b + 1;
} else if (p[x - 1] < p[j]) {
c = c + 1;
}
}
if (l + b == x) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
| ### Prompt
Please formulate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long hcf(long long a, long long b) {
if (b == 0) return a;
return hcf(b, a % b);
}
long long stringtoll(string s) {
long long ans = 0;
for (int i = 0; i < s.length(); i++) ans = ans * 10 + (s[i] - '0');
return ans;
}
vector<long long> allroot(long long n) {
vector<long long> ans;
for (long long i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
ans.push_back(i);
if (i != n / i) ans.push_back(n / i);
}
}
return ans;
}
bool prime(long long n) {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) return false;
}
return true;
}
long long logi(long long n, long long base) { return (log(n) / log(base)); }
long long mulmod(long long a, long long b, long long c) {
if (b == 0) return 0;
long long s = mulmod(a, b / 2, c);
if (b % 2 == 1)
return (a % c + 2 * (s % c)) % c;
else
return (2 * (s % c)) % c;
}
long long factorial(long long n) {
if (n == 0) return 1;
return (n * factorial(n - 1)) % 1000000007;
}
bool right(long long val, long long l, long long r) {
if (val >= l && val <= r) return true;
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, m;
cin >> n >> m;
long long p[n];
for (long long i = 0; i < n; i++) cin >> p[i];
int b = 0;
int c = 0;
for (int i = 0; i < m; i++) {
int b = 0;
int c = 0;
int l, r, x;
cin >> l >> r >> x;
for (int j = l - 1; j < r; j++) {
if (p[x - 1] > p[j]) {
b = b + 1;
} else if (p[x - 1] < p[j]) {
c = c + 1;
}
}
if (l + b == x) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> p;
p.push_back(0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
p.push_back(x);
}
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
int less = 0;
for (int j = l; j <= r; j++) {
if (p[j] < p[x]) less++;
}
if (x - l == less) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> p;
p.push_back(0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
p.push_back(x);
}
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
int less = 0;
for (int j = l; j <= r; j++) {
if (p[j] < p[x]) less++;
}
if (x - l == less) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int arr[10050];
int main() {
int n, m;
int l, r, x;
int cnt;
while (~scanf("%d%d", &n, &m)) {
for (int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
}
for (int i = 0; i < m; i++) {
cnt = 0;
scanf("%d%d%d", &l, &r, &x);
for (int j = l; j <= r; j++) {
if (arr[j] < arr[x]) cnt++;
}
if (cnt == x - l)
printf("Yes\n");
else
printf("No\n");
}
}
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int arr[10050];
int main() {
int n, m;
int l, r, x;
int cnt;
while (~scanf("%d%d", &n, &m)) {
for (int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
}
for (int i = 0; i < m; i++) {
cnt = 0;
scanf("%d%d%d", &l, &r, &x);
for (int j = l; j <= r; j++) {
if (arr[j] < arr[x]) cnt++;
}
if (cnt == x - l)
printf("Yes\n");
else
printf("No\n");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d %d", &n, &m);
vector<int> p(n);
for (int i = 0; i < n; i++) scanf("%d", &p[i]);
for (int i = 0; i < m; i++) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
if (x < l || x > r) {
printf("Yes\n");
continue;
}
int cnt = 0, f = 0;
for (int j = l - 1; j < r; j++) {
if (p[j] < p[x - 1]) cnt++;
if (cnt > x - l) {
printf("No\n");
f = 1;
break;
}
}
if (f) continue;
if (cnt == x - l)
printf("Yes\n");
else
printf("No\n");
}
}
| ### Prompt
Create a solution in cpp for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d %d", &n, &m);
vector<int> p(n);
for (int i = 0; i < n; i++) scanf("%d", &p[i]);
for (int i = 0; i < m; i++) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
if (x < l || x > r) {
printf("Yes\n");
continue;
}
int cnt = 0, f = 0;
for (int j = l - 1; j < r; j++) {
if (p[j] < p[x - 1]) cnt++;
if (cnt > x - l) {
printf("No\n");
f = 1;
break;
}
}
if (f) continue;
if (cnt == x - l)
printf("Yes\n");
else
printf("No\n");
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d", &n);
scanf("%d", &m);
int p[n];
string s = "Yes";
string s1 = "No";
int o[m];
for (int i = 0; i < n; i++) {
scanf("%d", &p[i]);
}
int l[m];
int r[m];
int x[m];
for (int i = 0; i < m; i++) {
scanf("%d", &l[i]);
l[i]--;
scanf("%d", &r[i]);
r[i]--;
scanf("%d", &x[i]);
x[i]--;
o[i] = l[i];
int q = p[x[i]];
for (int j = l[i]; j <= r[i]; j++) {
if (q >= p[j]) o[i]++;
}
}
for (int i = 0; i < m; i++) {
if (o[i] - 1 == x[i])
printf("\n%s", s.c_str());
else
printf("\n%s", s1.c_str());
}
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d", &n);
scanf("%d", &m);
int p[n];
string s = "Yes";
string s1 = "No";
int o[m];
for (int i = 0; i < n; i++) {
scanf("%d", &p[i]);
}
int l[m];
int r[m];
int x[m];
for (int i = 0; i < m; i++) {
scanf("%d", &l[i]);
l[i]--;
scanf("%d", &r[i]);
r[i]--;
scanf("%d", &x[i]);
x[i]--;
o[i] = l[i];
int q = p[x[i]];
for (int j = l[i]; j <= r[i]; j++) {
if (q >= p[j]) o[i]++;
}
}
for (int i = 0; i < m; i++) {
if (o[i] - 1 == x[i])
printf("\n%s", s.c_str());
else
printf("\n%s", s1.c_str());
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
int p[n];
int i, j;
for (i = 0; i < n; i++) cin >> p[i];
for (i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
int len = r - l + 1;
int a[len], k = 0;
for (j = l; j <= r; j++) a[k++] = p[j];
int llen = x - l;
int rlen = r - x;
int lcount = 0, rcount = 0;
int flag = 0;
for (j = 0; j < len; j++) {
if (a[j] < p[x])
lcount++;
else if (a[j] > p[x])
rcount++;
if (lcount > llen) {
flag++;
break;
}
if (rcount > rlen) {
flag++;
break;
}
}
if (flag == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
int p[n];
int i, j;
for (i = 0; i < n; i++) cin >> p[i];
for (i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
int len = r - l + 1;
int a[len], k = 0;
for (j = l; j <= r; j++) a[k++] = p[j];
int llen = x - l;
int rlen = r - x;
int lcount = 0, rcount = 0;
int flag = 0;
for (j = 0; j < len; j++) {
if (a[j] < p[x])
lcount++;
else if (a[j] > p[x])
rcount++;
if (lcount > llen) {
flag++;
break;
}
if (rcount > rlen) {
flag++;
break;
}
}
if (flag == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
int arr[10004];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int _k = (1), _n = (n), i = _k; i <= _n; ++i) scanf("%d", &arr[i]);
for (int _k = (1), _n = (m), i = _k; i <= _n; ++i) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
int t = 0, a = arr[x];
for (int _k = (l), _n = (r), j = _k; j <= _n; ++j)
if (arr[j] < a) ++t;
if (l + t == x)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
int arr[10004];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int _k = (1), _n = (n), i = _k; i <= _n; ++i) scanf("%d", &arr[i]);
for (int _k = (1), _n = (m), i = _k; i <= _n; ++i) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
int t = 0, a = arr[x];
for (int _k = (l), _n = (r), j = _k; j <= _n; ++j)
if (arr[j] < a) ++t;
if (l + t == x)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r) {
return (mt_rnd_64() % (r - l + 1)) + l;
}
using ll = long long;
using ld = long double;
using ull = unsigned long long;
const double PI = acos(-1.0);
const ll mod = 1e9 + 9;
const ll INF = 1e9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, m;
cin >> n >> m;
vector<ll> a(n);
for (ll &i : a) {
cin >> i;
}
ll l, r, x;
while (m--) {
cin >> l >> r >> x;
--l;
--r;
--x;
ll c = 0;
for (ll i = l; i <= r; ++i) {
if (a[i] < a[x]) ++c;
}
if (l + c == x) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r) {
return (mt_rnd_64() % (r - l + 1)) + l;
}
using ll = long long;
using ld = long double;
using ull = unsigned long long;
const double PI = acos(-1.0);
const ll mod = 1e9 + 9;
const ll INF = 1e9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, m;
cin >> n >> m;
vector<ll> a(n);
for (ll &i : a) {
cin >> i;
}
ll l, r, x;
while (m--) {
cin >> l >> r >> x;
--l;
--r;
--x;
ll c = 0;
for (ll i = l; i <= r; ++i) {
if (a[i] < a[x]) ++c;
}
if (l + c == x) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.