First line contains two space-separated integersn,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 integersp1, p2, ..., pn (1 ≤ pi ≤ n) — permutationP. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integersli,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.
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.
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Yes
No
Yes
Yes
No
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Yes
No
Yes
No
Yes
Explanation of first test case:
- [1, 2, 3, 4, 5] — permutation after sorting,3-rd element hasn’t changed, so answer is "Yes".
- [3, 4, 5, 2, 1] — permutation after sorting,1-st element has changed, so answer is "No".
- [5, 2, 3, 4, 1] — permutation after sorting,3-rd element hasn’t changed, so answer is "Yes".
- [5, 4, 3, 2, 1] — permutation after sorting,4-th element hasn’t changed, so answer is "Yes".
- [5, 1, 2, 3, 4] — permutation after sorting,3-rd element has changed, so answer is "No".
思路:只需判断[l,r]区间内小于x下标的个数count,判断排序后的位置l+count是否等于x即可
result:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
//sort在算法里是排序的意思,注意题意
//判断排序后index.x是不是在中间的位置 只需要判断区间内小于a[x]是不是等于x-l即可
int main()
{
vector<int> a;
int n,m,tmp;
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>tmp;
a.push_back(tmp);
}
int l,r,x;
while(m--){
cin>>l>>r>>x;
int count=0;
for(int i=l-1;i<r;i++)
{
if(a[i]<a[x-1])
count++;
}
if(count==x-l) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}