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
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
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".

题意就是一堆数,从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的更多相关文章

  1. codeforces 811 D. Vladik and Favorite Game(bfs水题)

    题目链接:http://codeforces.com/contest/811/problem/D 题意:现在给你一个n*m大小的图,你输出一个方向之后,系统反馈给你一个坐标,表示走完这步之后到的位子, ...

  2. codeforces 811 E. Vladik and Entertaining Flags(线段树+并查集)

    题目链接:http://codeforces.com/contest/811/problem/E 题意:给定一个行数为10 列数10w的矩阵,每个方块是一个整数, 给定l和r 求范围内的联通块数量 所 ...

  3. codeforces 811 C. Vladik and Memorable Trip(dp)

    题目链接:http://codeforces.com/contest/811/problem/C 题意:给你n个数,现在让你选一些区间出来,对于每个区间中的每一种数,全部都要出现在这个区间. 每个区间 ...

  4. 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 ...

  5. Codeforces 811 A. Vladik and Courtesy

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

  6. 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 ...

  7. Vladik and Complicated Book CodeForces - 811B (思维实现)

    Vladik had started reading a complicated book about algorithms containing n pages. To improve unders ...

  8. CodeForces 811B Vladik and Complicated Book

    离线,树状数组. 数据范围好像有点小,直接暴力可以过的. 我直接上了$n,Q≤100000$的做法:只需要判断区间上比$x$小的数字有几个即可,可以对询问进行离线操作,从左到右一个一个数字插入到树状数 ...

  9. 【35.02%】【codeforces 734A】Vladik and flights

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. 制作Windows10政府版的小白教程

    制作Windows10政府版的小白教程 https://03k.org/make10entg.html 首先,宿主系统要比操作的系统新,因为低版本dism操作不了: 当然也可以单独下载ADK,提取最新 ...

  2. cf 442 D. Olya and Energy Drinks

    cf 442 D. Olya and Energy Drinks(bfs) 题意: 给一张\(n \times m(n <= 1000,m <= 1000)\)的地图 给出一个起点和终点, ...

  3. BZOJ1857 [Scoi2010]传送带 【三分法】

    题目链接 BZOJ1857 题解 画画图就发现实际上是在\(AB\)上和\(CD\)上分别选两个点\(E\),\(F\),使得\(t_{AE} + t_{EF} + t_{FD}\)最小 然后猜想到当 ...

  4. bzoj2827: 千山鸟飞绝 平衡树 替罪羊树 蜜汁标记

    这道题首先可以看出坐标没有什么意义离散掉就好了. 然后你就会发现你要每次都更改坐标,而一旦更改受影响的是坐标里的所有数,要是一个一个的改,会不可描述. 所以换个视角,我们要找的是某只鸟所到每个坐标时遇 ...

  5. ionic2 手风琴效果

    user.ts import { Component } from '@angular/core';import { IonicPage, NavController, NavParams } fro ...

  6. 理解[].forEach.call()

    例子: let cols = document.querySelectorAll('ul li') [].forEach.call(cols, function (col, index) { // T ...

  7. HttpClientUntils工具类的使用测试及注意事项(包括我改进的工具类和Controller端的注意事项【附 Json 工具类】)

    HttpClient工具类(我改过): package com.taotao.httpclient; import java.io.IOException; import java.net.URI; ...

  8. Clevo P950笔记本加装4G模块

    要补全的电路部分如下(原理图见附件) 这里经过尝试,发现左上角R217,R218不用接,3G_POWER部分不接(包括MTS3572G6.UK3018及电阻电容,3G_PWR_EN实测是3.3V,驱动 ...

  9. CMU Bomblab 答案

    室友拉我做的... http://csapp.cs.cmu.edu/3e/labs.html Border relations with Canada have never been better. ...

  10. bzoj 2304 [Apio2011]寻路 Dij+模拟+恶心建图

    [Apio2011]寻路 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 624  Solved: 193[Submit][Status][Discus ...