CodeForces
来源:互联网 发布:5g网络的概念 编辑:程序博客网 时间:2024/06/05 19:14
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 pxchanged? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
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.
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 55 4 3 2 11 5 31 3 12 4 34 4 42 5 3
YesNoYesYesNo
6 51 4 3 2 5 62 4 31 6 24 5 41 3 32 6 3
YesNoYesNoYes
题目大概:
输出一段序列,给指定段重新排序,然后看指定位置的数字是否改变。
思路:
不能用排序,否则TLE。
代码:
#include <iostream>#include<cstdio>#include<cstring>#include<vector>#include<queue>#include<algorithm>using namespace std;int n,m;int a[10003];int b[10003];int main(){cin>>n>>m;int i=1;while(i!=n+1){ scanf("%d",&a[i]); b[i]=a[i]; i++;}while(m--){ int l,r,k; scanf("%d%d%d",&l,&r,&k); int sum=0; for(int i=l;i<=r;i++) { if(a[i]<a[k])sum++; } if(sum==k-l)printf("Yes\n"); else printf("No\n");} return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- XWiki initialization failed!
- 进程信息之getrusage系统调用
- PPT排版细节,写给大家看的设计书,完美总结
- javaScript中的函数定义
- 输入某年某月某日,计算出今天是今年的第几天
- CodeForces
- 为什么不能用返回值类型来判断方法是否重载呢?
- 前 、中、后缀表达式
- java程序初始化的过程
- 深入理解Linux系统负载
- Python学习第一章:第一次的亲密接触(一)
- java算法--线性表
- The Rotation Game UVA
- 编程经验笔记