CodeForce 811 B Vladik and Complicated Book

来源:互联网 发布:淘宝运营自我介绍 编辑:程序博客网 时间:2024/06/05 22:35

题目链接:点击打开链接

B. Vladik and Complicated Book
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 nm (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 lirixi (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 55 4 3 2 11 5 31 3 12 4 34 4 42 5 3
output
YesNoYesYesNo
input
6 51 4 3 2 5 62 4 31 6 24 5 41 3 32 6 3
output
YesNoYesNoYes
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".

题意是给你一组数和几次操作,下面给出m组数据,包括一个区间和一个位置。需要对区间进行排序,问排序后是否还是当前的数字。

排序是肯定超时的,要判断修改后这个位置的数的前面有多少数字,是否等于以前个数的和。水题,但我以为是交换,没看懂是排序。


代码实现:


#include<iostream>#include<algorithm>#include<cstring>using namespace std;int main(){int b[10005],x,y,z,m,n,i,j;while(cin>>m>>n){for(i=0;i<m;i++)cin>>b[i];for(i=0;i<n;i++)  {cin>>x>>y>>z;   //输入区间和数字 int count=0;    for(j=x-1;j<y;j++)    //区间遍历 {if(b[j]<b[z-1])   //记录比第z个数字小的那一个 count++;}if(count==z-x)     //如果,比第z个数字小的个数等于区间内z左边的数字 cout<<"Yes"<<endl;elsecout<<"No"<<endl; }}return 0;}


原创粉丝点击