GTY has nn gay friends. To manage them conveniently, every morning he ordered all his gay friends to stand in a line. Every gay friend has a characteristic value aiai , to express how manly or how girlish he is. You, as GTY's assistant, have to answer GTY's queries. In each of GTY's queries, GTY will give you a range [l,r][l,r] . Because of GTY's strange hobbies, he wants there is a permutation [1..r−l+1][1..r−l+1] in [l,r][l,r]. You need to let him know if there is such a permutation or not.

InputMulti test cases (about 3) . The first line contains two integers n and m ( 1≤n,m≤10000001≤n,m≤1000000 ), indicating the number of GTY's gay friends and the number of GTY's queries. the second line contains n numbers seperated by spaces. The ithith number aiai ( 1≤ai≤n1≤ai≤n ) indicates GTY's ithith gay friend's characteristic value. The next m lines describe GTY's queries. In each line there are two numbers l and r seperated by spaces ( 1≤l≤r≤n1≤l≤r≤n ), indicating the query range.OutputFor each query, if there is a permutation [1..r−l+1][1..r−l+1] in [l,r][l,r], print 'YES', else print 'NO'.Sample Input

8 5
2 1 3 4 5 2 3 1
1 3
1 1
2 2
4 8
1 5
3 2
1 1 1
1 1
1 2

Sample Output

YES
NO
YES
YES
YES
YES
NO 题意 给出一个数列,询问连续的从l开始到r为止的数是否刚好能够组成从1开始到r-l+1的数列 第一个判断用前缀和求和,然后就是查重
用线段树维护每一个数它上一次出现的地方,
如果这个区间里面所有的数上一次出现的最大值小于了a 那就是符合条件的了
 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define rtl rt<<1
#define rtr rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define name2str(x) #x
#define fuck(x) cout<<#x" = "<<x<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)+
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("in.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int mod = 1e9 + ;
const int maxn = 1e6 + ;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
int n, m, x, vis[maxn];
LL sum[maxn];
struct node {
int l, r, num;
int mid() {
return ( l + r ) >> ;
}
} tree[maxn << ];
void pushup ( int rt ) {
tree[rt].num = max ( tree[rtl].num, tree[rtr].num );
}
void build ( int l, int r, int rt ) {
tree[rt].l = l, tree[rt].r = r;
if ( l == r ) {
tree[rt].num = ;
return ;
}
int m = ( l + r ) >> ;
build ( l, m, rtl );
build ( m + , r, rtr );
}
void update ( int pos, int key, int rt ) {
if ( tree[rt].l == tree[rt].r ) {
tree[rt].num += key;
return ;
}
int m = tree[rt].mid();
if ( pos <= m ) update ( pos, key, rtl );
else update ( pos, key, rtr );
pushup ( rt );
}
int query ( int L, int R, int rt ) {
if ( L <= tree[rt].l && tree[rt].r <= R ) return tree[rt].num;
int m = tree[rt].mid();
if ( L > m ) return query ( L, R, rtr );
else if ( R <= m ) return query ( L, R, rtl );
else return max ( query ( L, m, rtl ), query ( m + , R, rtr ) );
}
int main() {
while ( ~sff ( n, m ) ) {
mem ( vis, );
build ( , n, );
for ( int i = ; i <= n ; i++ ) {
sf ( x );
sum[i] = sum[i - ] + x;
if ( vis[x] ) update ( i, vis[x], );
vis[x] = i;
}
while ( m-- ) {
int a, b;
sff ( a, b );
// fuck(sum[b] - sum[a - 1]),fuck(( b - a + 1 ) * ( b - a + 2 ) / 2)
if ( sum[b] - sum[a - ] == ( b - a + ) * ( b - a + ) / && query ( a, b, ) < a ) printf ( "YES\n" );
else printf ( "NO\n" );
}
}
return ;
}
 

GTY's gay friends HDU - 5172 线段树的更多相关文章

  1. hdu 5172(线段树||HASH)

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

  2. hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  3. hdu 3974 线段树 将树弄到区间上

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. hdu 3436 线段树 一顿操作

    Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  5. hdu 3397 线段树双标记

    Sequence operation Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. hdu 4578 线段树(标记处理)

    Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) ...

  7. hdu 4533 线段树(问题转化+)

    威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Tot ...

  8. hdu 2871 线段树(各种操作)

    Memory Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  9. hdu 4052 线段树扫描线、奇特处理

    Adding New Machine Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. 《图解 HTTP 》阅读 —— 第三章

    第3章 HTTP 报文内的 HTTP 信息 用于 HTTP 协议交互的信息称为 HTTP 报文:请求报文和响应报文 HTTP 在传输数据时通过编码可以提升速率,能有效的处理大量数据,但是会消耗更多的C ...

  2. thinkphp5框架生成二维码(二)

    上篇已经讲过了SDK之类的,这个不再重复,有不知道的童鞋们,请去看上篇文章吧. 这里我用的方法比较老旧,大家有更好的方法,可以进行改良,还有linux服务器,记得给文件权限,否则生成的文件会失败的.大 ...

  3. linux下搭建python机器学习环境

    前言 在 linux 下搭建 python 机器学习环境还是比较容易的,考虑到包依赖的问题,最好建立一个虚拟环境作为机器学习工作环境,在建立的虚拟环境中,再安装各种需要的包,主要有以下6个(这是看这个 ...

  4. [笔记] FreeBSD使用小技巧

    非交互式添加用户 sed直接修改文件 sed -i '' 's/a/b/' file sed添加一行 sed '1a\ newline' file sed '1s/.*/&\'$'\nnewl ...

  5. centos上搭建git服务--2

    在 Linux 下搭建 Git 服务器   环境: 服务器 CentOS6.6 + git(version 1.7.1)客户端 Windows10 + git(version 2.8.4.window ...

  6. PHP中的数据类型

    PHP中包含8种数据类型,其中包括4种标量:整型,浮点型,字符串,布尔值:2种复合类型:数组和对象:一种resource类型,剩下的一种是NULL类型. 整型 PHP中的整型可以是负,也可以是正,而整 ...

  7. 0329--Scrum团队准备工作

    一.团队名称,团队目标.团队口号.团队照 1.团队名称:Blackhriar 2.团队目标:完成一个完善的,可以投入市场供用户使用,甚至具有一定商业价值的项目~come on! 3.团队口号:抱怨事件 ...

  8. Scrum 项目6.0-展示Sprint回顾的过程及成果。

    6.0----------------------------------------------------- sprint演示 1.坚持所有的sprint都结束于演示. 团队的成果得到认可,会感觉 ...

  9. Python学习之路6 - 装饰器

    装饰器 定义:本质是函数,(装饰其他函数)就是为其他函数添加附加功能.原则:1.不能修改被装饰的函数的源代码 2.不能修改被装饰的函数的调用方式 实现装饰器的知识储备: 1.函数即“变量” 2.高阶函 ...

  10. zabbix简介

    (一)监控系统 初探 前言: 对于监控系统而言,首先必须搞清楚需要监控什么? (1)硬件设备和软件设备:服务器,路由器,交换机,I/O存储系统,操作系统,网络,各种应用程序 (2)各种指标:数据库宕机 ...