Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
来源:互联网 发布:aso优化面试该说些什么 编辑:程序博客网 时间:2024/06/05 22:37
time limit per test 2 seconds
memory limit per test 256 megabytes
Description
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
水…极水的模拟。
昨天写的时候,感觉数据量也不大,sort一下就过了样例
代码如下
#include<bits/stdc++.h>using namespace std;int n,m;int a[100005];int b[100005];int l,r,x;int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); b[i]=a[i]; } for(int i=0;i<m;i++) { scanf("%d%d%d",&l,&r,&x); sort(b+l,b+r+1); //for(int i=1;i<=n;i++) //printf("%d ",b[i]); //printf("%d %d\n",a[x-1],b[x-1]); if(b[x]==a[x]) printf("Yes\n"); else printf("No\n"); for(int i=l;i<=r;i++) b[i]=a[i]; }}
然而最后重新测数据,还是给hack了 (╯‵□′)╯︵┻━┻
和我一个房间的两个印度人一直坚持不懈的hack了我8遍( ̄工 ̄lll),
然后他们成功了,居然给搞得TLE了,好气啊。
下面是AC代码,不多说了。
#include<bits/stdc++.h>using namespace std;int n,m;int a[100005];int l,r,x;int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } for(int i=0;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++; } if(cnt+x==r) printf("Yes\n"); else printf("No\n"); }}
- Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
- Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
- Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
- #416 Div.2 B. Vladik and Complicated Book
- Codeforces 811B Vladik and Complicated Book
- Codeforces 811 B Vladik and Complicated Book
- codeforces#416 div2- Vladik and Complicated Book
- B. Vladik and Complicated Book
- B. Vladik and Complicated Book
- Codeforces 811B Vladik and Complicated Book[主席树]
- CodeForce 811 B Vladik and Complicated Book
- Vladik and Complicated Book
- codeforces——811B——Vladik and Complicated Book
- CodeForces 811B——Vladik and Complicated Book ——思维,模拟
- codeforce Vladik and Complicated Book
- Codeforces Round #416 (Div. 2) A. Vladik and Courtesy
- Codeforces Round #416 (Div. 2)C. Vladik and Memorable Trip
- Codeforces Round #416 (Div. 2) A. Vladik and Courtesy
- 区块链编程一翻译篇<一>:web3j介绍
- 嵌入式SQL语言
- windows 证书管理
- SAP 修改物料价格那些事
- js实现点击按钮变换背景颜色
- Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
- windows安装composer问题
- 区块链编程一翻译篇<二>:web3j准备工作
- java中多态的方法调用
- 1010. Radix (25)(PAT甲)
- 笔记
- Go语言安装第三方库
- OpenStack在Uubutu上的一键安装
- 一种新的ResNet思路:Learning Identity Mapping with Residual Gates论文笔记