#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = +;
int res[MAX<<],ans[MAX],t[MAX];
int a[MAX],last[MAX];
struct node {
    int L,R,id,d;
    bool operator <(const node rhs) const {
        return R<rhs.R;
    }
}v[MAX];
void push_up(int o) {
   res[o]=max(res[o<<],res[o<<|]);
}
void build(int L,int R,int o) {
    if(L==R) {
        res[o]=a[L];
        return ;
    }
    int mid=(L+R)>>;
    build(L,mid,o<<);
    build(mid+,R,o<<|);
    push_up(o);
}
int Query1(int L,int R,int o,int ls,int rs) {
    if(ls<=L&&rs>=R) {
        return res[o];
    }     int mid=(L+R)>>;
    int tt=;
    if(ls<=mid) tt=max(tt,Query1(L,mid,o<<,ls,rs));
    if(rs>mid) tt=max(tt,Query1(mid+,R,o<<|,ls,rs));
    return tt;
}
int sum[MAX];
int lowbit(int x) {
    return x&-x;
}
void modify(int pos,int val) {
    for(int i=pos;i<MAX;i+=lowbit(i)) {
        sum[i]+=val;
    }
}
int Query(int pos) {
    int res=;
    for(int i=pos;i;i-=lowbit(i)) {
        res+=sum[i];
    }
    return res;
}
int main() {
    int n,m;
    while(scanf("%d %d",&n,&m)==) {
        for(int i=;i<=n;i++) {
            scanf("%d",&a[i]);
        }
        build(,n,);
        for(int i=;i<=m;i++) {
            scanf("%d %d",&v[i].L,&v[i].R) ;
            v[i].id=i;
            v[i].d=(v[i].R-v[i].L+);
        }
        sort(v+,v++m);
        memset(sum,,sizeof(sum));
        memset(last,,sizeof(last));
        int j=;         for(int i=;i<=n;i++) {
            if(last[a[i]]) {
                modify(last[a[i]],-);
            }
            modify(i,);
            last[a[i]]=i;
            while(i==v[j].R&&j<=m) {                 ans[v[j].id]=Query(v[j].R)-Query(v[j].L-);
              //  printf("%d %d %d\n",ans[v[j].id],v[j].d,Query1(1,n,1,v[j].L,v[j].R));
                if(ans[v[j].id]==v[j].d&&Query1(,n,,v[j].L,v[j].R)==v[j].d) {
                    t[v[j].id]=;
                }
                else t[v[j].id]=;
                j++;
            }
        }
        for(int i=;i<=m;i++) {
            if(t[i]) printf("YES\n");
            else printf("NO\n");
        }
    }
    return ;
}

BestCoder Round #29 GTY's gay friends的更多相关文章

  1. BestCoder Round #29 1003 (hdu 5172) GTY's gay friends [线段树 判不同 预处理 好题]

    传送门 GTY's gay friends Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  2. BestCoder Round #29——A--GTY's math problem(快速幂(对数法))、B--GTY's birthday gift(矩阵快速幂)

    GTY's math problem Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  3. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  4. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  5. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  6. Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  7. Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  8. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  9. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

随机推荐

  1. magento controller直接渲染Block 以及传参

    class Jago_Deal_IndexController extends Mage_Core_Controller_Front_Action { public function ajaxActi ...

  2. [转]mysql日志详细解析

    转自:http://pangge.blog.51cto.com/6013757/1319304 MySQL日志: 主要包含:错误日志.查询日志.慢查询日志.事务日志.二进制日志: 日志是mysql数据 ...

  3. [转]探索 Windows Azure Storage

    本文转自:https://msdn.microsoft.com/zh-tw/jj573842 概觀 儲存服務 (Storage services) 在 Windows Azure 運算模擬器中提供了可 ...

  4. 001原始编译全志r6平台tinav3.0.2系统

    001原始编译全志r6平台tinav3.0.2系统 2018/6/8 11:32 版本:V1.0 开发板:R6 SDK:tina v3.0.2 1.01原始编译全志r16平台tinav3.0系统: r ...

  5. CCF|跳一跳

    import java.util.Scanner; public class Main { public static void main (String[] args) { Scanner scan ...

  6. 掌握Spark机器学习库-07-最小二乘法

    1)最小化残差平方和 2)原理,推导过程 3)例子

  7. linux下安装mysql5.7.21

    下载 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz 解压 ...

  8. 【C++】模板简述(四):模板为什么不支持分离编译?

    上文简述了类模板相关功能,本文主要简述为什么模板不支持分离编译? 在C++中,为了一个项目的规范,我们通常把代码归为三类:声明文件.实现文件.测试文件. 比如,我要用C++实现一个链表,那么就会创建这 ...

  9. SweetAlert如何实现点击Confirm之后自动关闭

    swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary ...

  10. WM

    #define WM_NULL 0x0000 #define WM_CREATE 0x0001 #define WM_DESTROY 0x0002 #define WM_MOVE 0x0003 #de ...