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
  1. 5 5
    5 4 3 2 1
    1 5 3
    1 3 1
    2 4 3
    4 4 4
    2 5 3
output
  1. Yes
    No
    Yes
    Yes
    No
input
  1. 6 5
    1 4 3 2 5 6
    2 4 3
    1 6 2
    4 5 4
    1 3 3
    2 6 3
output
  1. Yes
    No
    Yes
    No
    Yes
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".

解题思路:

这道题简单的一笔,就是当时打的时候算了下复杂度懒得跟他多比比,直接暴力过了,结果被人出了个极限数据卡了时间复杂度,mmp!

被hack了,下面直接放代码,没啥讲的。以后不能瞎暴力了,要不迟早要翻水水

实现代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1e4 + ;
  4. int n, m, a[N];
  5.  
  6. int main() {
  7. cin>>n>>m;
  8. for (int i = ; i <= n; i++) cin>>a[i];
  9. while (m--) {
  10. int l, r, x; cin>>l>>r>>x;
  11. int cnt = ;
  12. for (int i = l; i <= r; i++) {
  13. if (a[i] < a[x]) cnt++;
  14. }
  15. if (x == l + cnt)
  16. cout<<"Yes"<<endl;
  17. else
  18. cout<<"No"<<endl;
  19. }
  20. }

Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book的更多相关文章

  1. Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game

    地址:http://codeforces.com/contest/811/problem/D 题目: D. Vladik and Favorite Game time limit per test 2 ...

  2. Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip

    http://codeforces.com/contest/811/problem/C 题意: 给出一行序列,现在要选出一些区间来(不必全部选完),但是相同的数必须出现在同一个区间中,也就是说该数要么 ...

  3. Codeforces Round #416 (Div. 2) A. Vladik and Courtesy【思维/模拟】

    A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. 【分类讨论】【spfa】【BFS】Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game

    那个人第一步肯定要么能向下走,要么能向右走.于是一定可以判断出上下是否对调,或者左右是否对调. 然后他往这个方向再走一走就能发现一定可以再往旁边走,此时就可以判断出另一个方向是否对调. 都判断出来以后 ...

  5. 【动态规划】 Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip

    划分那个序列,没必要完全覆盖原序列.对于划分出来的每个序列,对于某个值v,要么全都在该序列,要么全都不在该序列.  一个序列的价值是所有不同的值的异或和.整个的价值是所有划分出来的序列的价值之和.   ...

  6. Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)

    A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  7. Codeforces Round#416 Div.2

    A. Vladik and Courtesy 题面 At regular competition Vladik and Valera won a and b candies respectively. ...

  8. Codeforces Round #416 (Div. 2) A+B

    A. Vladik and Courtesy 2 seconds 256 megabytes   At regular competition Vladik and Valera won a and  ...

  9. Codeforces Round #416 (Div. 2)A B C 水 暴力 dp

    A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. 解析LED发光效率

    解析LED发光效率 来源:--作者:--浏览:532时间:2016-08-10 14:18 关键词: 发光效率为评测光源效率的指标,用光源发出的光通量 (lm)与向光源输入的电力(W)之比表示.单位为 ...

  2. ASP.NET MVC学习笔记(一) 从路由开始创建mvc

    之前一篇写一半发现版本太老了,是基于mvc2的. 两本参考书编写的顺序各方面都不太一样.决定重新写一篇. 我这篇文章基于mvc5,vs2015 参考书:Will保哥的ASP.NET MVC4开发指南 ...

  3. Luogu4173 残缺的字符串 FFT

    传送门 考虑如何使用FFT计算两个子串是否匹配.如果字符集比较小可以把每个字符都拿出来暴力做一遍,但是字符集比较大的时候复杂度就会有问题.这个时候可以考虑匹配函数. 先考虑没有通配符的情况.将\(A\ ...

  4. 关于 CSLA 服务器部署WCF访问出错的问题

    MDAA项目 在以前的项目中,只要部署,从来没有发生过 通过WCF访问出错的问题,但是此次却出现如下问题: 2018-04-21 13:45:39,744 [119] ERROR Galaxy.OTC ...

  5. item 3: 理解decltype

    本文翻译自modern effective C++,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 博客已经迁移到这里啦 decltype是一个奇怪的东西.给出一个名字或者一个表达式,de ...

  6. Error【0007】:zabbix中因为curl版本过低而无法发送邮件

    1. 错误背景 在centos6.5上,源码部署zabbix最新版本zabbix-3.2.14.部署后之后,在配置邮件发送报警时出错 2. 错误提示 3. 原因分析 从网上检索的结果是说,系统中的cu ...

  7. Wannafly挑战赛25 B.面积并

    链接 [https://www.nowcoder.com/acm/contest/197/B] 分析 特殊优先考虑 首先考虑r>=l这种情况就是圆的面积了 第二就是r<=内切圆的半径,这个 ...

  8. Hangfire Net Core2

    https://hangfire.jonecheung.win/configuration/using-redis.html Hangfire 官方支持 MSSQL 与 Redis(Hangfire. ...

  9. HTML DOM 学习笔记

    一.HTML DOM定义了所有HTML元素的对象和属性,以及访问他们的方法即:HTML DOM是关于如何获取,修改,添加,删除HTML元素的标准二.DOM节点1.分类整个文档是一个文档节点每个HTML ...

  10. NullPointerException-----开发中遇到的空指针异常

    1.使用CollectionUtils.isEmpty判断空集合 public class TestIsEmpty { static class Person{} static class Girl ...