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 ...
随机推荐
- hdu 1286 找新朋友 (欧拉函数)
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- [LOJ#6437][BZOJ5373]「PKUSC2018」PKUSC
[LOJ#6437][BZOJ5373]「PKUSC2018」PKUSC 试题描述 九条可怜是一个爱玩游戏的女孩子. 最近她在玩一个无双割草类的游戏,平面上有 \(n\) 个敌人,每一个敌人的坐标为 ...
- [BZOJ3196][Tyvj1730]二逼平衡树
[BZOJ3196][Tyvj1730]二逼平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 查询 \(k\) 在区间内的排名 查询区间内排名为 \ ...
- 理解First Chance和Second Chance避免单步调试
原文链接地址:http://blog.csdn.net/Donjuan/article/details/3859160 在现在C++.Java..Net代码大行其道的时候,很多代码错误(Bug)都是通 ...
- JavaScript使用数组拼接字符串性能如何?
传统上,字符串连接一直是js中性能最低的操作之一. view source print? 1 var text="Hello"; 2 text+=" World!&q ...
- Equal Sums (map的基本应用) 多学骚操作
C. Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 状压DP初识~~炮兵阵地
炮兵阵地 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31718 Accepted: 12253 Descriptio ...
- matlab求矩阵、向量的模
求矩阵的模: function count = juZhenDeMo(a,b) [r,c] = size(a);%求a的行列 [r1,c1] = size(b);%求b的行列 count = 0; f ...
- IOS 上传项目到github 终端操作
1.创建github账号 2.创建秘钥 3.Github配置秘钥 4.上传文件 复制保存网址 终端操作,如果没有ssh,自行安装 GitHub配置秘钥 克隆github上创建的项目 将自己的本地项目, ...
- Spring 学习笔记(三)之注解
一.在classpath下扫描组件 •组件扫描(component scanning): Spring 能够从 classpath 下自动扫描, 侦测和实例化具有特定注解的组件. •特定组件包括: ...