GTY's gay friends HDU - 5172 线段树
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 线段树的更多相关文章
- hdu 5172(线段树||HASH)
GTY's gay friends Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 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 ...
- hdu 3974 线段树 将树弄到区间上
Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3436 线段树 一顿操作
Queue-jumpers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu 3397 线段树双标记
Sequence operation Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 4578 线段树(标记处理)
Transformation Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others) ...
- hdu 4533 线段树(问题转化+)
威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- hdu 2871 线段树(各种操作)
Memory Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 4052 线段树扫描线、奇特处理
Adding New Machine Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
随机推荐
- 当git遇上中文乱码
git有个比较奇怪的问题,当目录或者文件名中出现了中文的时候,在执行git status 的时候,会返回一串unicode码,这段unicode码就读不懂了,必须解决. git status显示uni ...
- 阿里巴巴将在美国推出电子商务网站11 Main
新浪科技讯 北京时间2月11日晚间消息,阿里巴巴集团周二向路透社证实,阿里巴巴将通过旗下子公司Vendio和Auctiva在美国推出一个电子商务网站. 该网站的名称为“11 Main”(11main. ...
- 产品需求文档(PRD)的写作 【转】
产品需求文档(PRD)的写作 一.文章的摘要介绍 无论我们做什么事都讲究方式方法,写产品需求文档(以下称PRD文档)也是如此,之前我通过四篇文章分享了自己写PRD文档的一些方法,而这一篇文章主要是 ...
- socket发送文字、图片、文件---基于python实现
socket官方文档:https://docs.python.org/2/library/socket.html socket中文详细介绍:http://blog.csdn.net/rebelqsp/ ...
- scrum立会报告+燃尽图(第三周第五次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2286 项目地址:https://coding.net/u/wuyy694 ...
- Java 学习笔记 ------第五章 对象封装
本章学习目标: 了解封装的概念与实现 定义类.构造函数与方法 使用方法重载与不定长度自变量 了解static方法 一.Java封装概念 在面向对象程式设计方法中,封装(英语:Encapsulation ...
- 对首师大研究生院的UI分析
我们分析的是首都师范大学研究生院的UI界面 网站链接http://grad.cnu.edu.cn/index.htm 学校设计和石家庄铁道大学的界面类似,都是有一个大的置顶的名字,将学校或者学院的名字 ...
- ARP 攻击
场景 A攻击者 192.168.1.3 00:00:00:00:00:01 B受害者 192.168.1.2 00:00:00:00:00:02 C路由器 192.168.1.1 00:00:00:0 ...
- 1106C程序语法树
- C语言文法翻译
<程序>→<外部声明>|<程序><外部声明> <外部声明>→<函数定义>|<声明> <函数定义>→< ...