#416 Div.2 B. Vladik and Complicated Book - 排序&技巧

B. Vladik and Complicated Book
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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

大意:
给出一个序列,有m个询问。
每次给出端点 l ,r 对区间 [ l , r ] 中进行 sort 操作。求 位置 x 是否还为原来的数字。
思路:
sort 明显超时。数字不变,当且仅当 x 在 [ l , r ] 中的左边比 x 大的数字个数与 x 右边比 x 小的数字个数相等。

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
typedef long long ll;
#define D(v) cout<<#v<<" "<<v<<endl
#define inf 0x3f3f3f3f
int a[10005],num1[10005],num2[10005];
int main(){
    int n,m;
    memset(a,0,sizeof(a));
    memset(num1,0,sizeof(num1));
    memset(num2,0,sizeof(num2));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=m;i++){
        int l,r,x;
        scanf("%d%d%d",&l,&r,&x);
        if(l>r) swap(l,r);
        int cnt1=0,cnt2=0;
        for(int i=l;i<=x;i++){
            if(a[x]<=a[i])
                cnt1++;
        }
        for(int j=x;j<=r;j++){
            if(a[x]>=a[j])
                cnt2++;
        }
        if(cnt1==cnt2)
            puts("Yes");
        else puts("No");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值