Codeforces 811 B. Vladik and Complicated Book
2 seconds
256 megabytes
standard input
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.
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 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个数有没有变。
这个题如果用sort排序(时间复杂度O( n*log2(n) ))的话不行,会超时。
就换一个思路,统计l到r中有几个比第x个数小的数,然后统计的值和l到x中有几个数比较一下,如果相等,就不变,为Yes,否则为No;
A题写的好难过,还好B题一次就过了。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
int a[N];
int main(){
int n,m;
int h,k,l,num;
while(~scanf("%d%d",&n,&m)){
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
while(m--){
scanf("%d%d%d",&h,&k,&l);
num=0;
for(int i=h-1;i<=k-1;i++){
if(a[i]<a[l-1])
num++;
}
if(num==l-h) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
这个题让我又想起了一个乱七八糟的题,输出第x个?
二分不可以,用主席树,我写不出来。。。
Codeforces 811 B. Vladik and Complicated Book的更多相关文章
- codeforces 811 D. Vladik and Favorite Game(bfs水题)
题目链接:http://codeforces.com/contest/811/problem/D 题意:现在给你一个n*m大小的图,你输出一个方向之后,系统反馈给你一个坐标,表示走完这步之后到的位子, ...
- codeforces 811 E. Vladik and Entertaining Flags(线段树+并查集)
题目链接:http://codeforces.com/contest/811/problem/E 题意:给定一个行数为10 列数10w的矩阵,每个方块是一个整数, 给定l和r 求范围内的联通块数量 所 ...
- codeforces 811 C. Vladik and Memorable Trip(dp)
题目链接:http://codeforces.com/contest/811/problem/C 题意:给你n个数,现在让你选一些区间出来,对于每个区间中的每一种数,全部都要出现在这个区间. 每个区间 ...
- Codeforces 811 C. Vladik and Memorable Trip
C. Vladik and Memorable Trip time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- Codeforces 811 A. Vladik and Courtesy
A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
B. Vladik and Complicated Book time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- Vladik and Complicated Book CodeForces - 811B (思维实现)
Vladik had started reading a complicated book about algorithms containing n pages. To improve unders ...
- CodeForces 811B Vladik and Complicated Book
离线,树状数组. 数据范围好像有点小,直接暴力可以过的. 我直接上了$n,Q≤100000$的做法:只需要判断区间上比$x$小的数字有几个即可,可以对询问进行离线操作,从左到右一个一个数字插入到树状数 ...
- 【35.02%】【codeforces 734A】Vladik and flights
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- [洛谷P3376]【模板】网络最大流(ISAP)
C++ Code:(ISAP) #include <cstdio> #include <cstring> #define maxn 1210 #define maxm 1200 ...
- BZOJ 2226 [Spoj 5971] LCMSum | 数论拆式子
题目: http://www.lydsy.com/JudgeOnline/problem.php?id=2226 题解: 题目要求的是Σn*i/gcd(i,n) i∈[1,n] 把n提出来变成Σi/g ...
- input checkbox 多选 验证
# input checkbox 多选 验证``` <ul class="orderMsg_radio"> <!--单选--> <input valu ...
- 用filters定制化spring的包扫描
Fiter的信息如下: Filter的类型有:annotation(这是spring默认的),assignable,aspectj, regex,custom 首先看一下我这个demo的目录结构: 上 ...
- rpm的使用:查询、安装、卸载、升级
RPM 有五种操作模式,分别为:安装.卸载.升级.查询和验证. RPM 安装操作 命令: rpm -i 需要安装的包文件名 举例如下: rpm -i example.rpm 安装 example.rp ...
- php-instanceof运算符
1.关于 instanceof 的一些基本概念 1).instanceof 用于确定一个PHP变量是否属于某一类class的实例: <?php class MyClass { } class N ...
- ActiveMQ(4) ActiveMQ JDBC 持久化 Mysql 数据库
ActiveMQ 消息持久化机制: ActiveMQ 消息的持久化机制有 JDBC.AMQ.KahaDB 和 LevelDB,其中本示例版本(5.15.2)默认机制为 KahaDB.无论哪种持久化机制 ...
- CSS选择器及CSS3新增选择器
转自:http://www.cnblogs.com/libingql/p/4375354.html 1. CSS1定义的选择器 选择器 类型 说明 E 类型选择器 选择指定类型的元素 E#id ID选 ...
- Mybatis如何查询部分字段
解决问题:数据库表里面很多字段不太需要,有时只想取到里面的部分字段的值,如果重新定义 DTO 会比较麻烦. BookMapper.xml 文件中定义如下: ` <!-- Book全部字段 --& ...
- PCIe 中的Capability 结构的寻址
PCI-X 和PCIe 总线规范要求其设备必须支持Capabilities 结构.在PCI 总线的基本配置空间中,包含一个Capabilities Pointer 寄存器,该寄存器存放Capabili ...