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 ...
随机推荐
- HackRF One硬件架构及参数简介
本文内容.开发板及配件仅限用于学校或科研院所开展科研实验! 淘宝店铺名称:开源SDR实验室 HackRF链接:https://item.taobao.com/item.htm?spm=a1z10.1- ...
- http 502 bad gate way
世界杯期间,公司的cdn在回源时突然出现大量502. 刚出现问题时,因为考虑到一般502都是上游服务器出现问题,然后因为已经服务了很久都没有出现过这种问题, 就没有仔细考虑,就让回源中心的同事进行排查 ...
- Linux环境下Java应用性能分析定位-CPU使用篇
1 CPU热点分析定位背景 CPU资源还是很昂贵的,为了深刻感受到这种昂贵,间下图当前CPU的资源售价: 所以对于程序猿们来说,需要让程序合理高效的使用CPU资源.利用有限的CPU资源来解决完 ...
- 微软职位内部推荐-Principal Group Program Manager
微软近期Open的职位: Standard job title: Principal Group Program Manager Discipline: Program Management Prod ...
- ShipStation Now Uses AWS And Amazon Fulfillment To Automatically Ship From eBay, Sears And Other Marketplaces
ShipStation today unveiled a first-of-its-kind service to leverage Amazon Web Services and Amazon.co ...
- KETTLE元数据表
表名 说明 R_CLUSTER R_CLUSTER_SLAVE R_CONDITION R_DATABASE 数据库连接信息 R_DATABASE_ATTRIBUTE 数据库属性 R_DATABASE ...
- flask验证登录学习过程(1)---实践flask_jwt
flask_jwt应用代码: from flask import Flask from flask_jwt import JWT,jwt_required,current_identity from ...
- FivePlus——成果展示
思路描述:描述对于自己此次任务是如何思考的 这次作业没能帮上什么忙,刚开始还对这次作业有所期待,然而,第一次听他们讨论的时候就??? 之后又去查了一些诸如贪吃蛇类的小游戏,知道大概可以达成什么效果,但 ...
- UVALive 6913 I Want That Cake 博弈+dp
题目链接: http://acm.hust.edu.cn/vjudge/problem/96343 I Want That Cake Time Limit: 3000MS 64bit IO Forma ...
- [图算法] 1030. Travel Plan (30)
1030. Travel Plan (30) A traveler's map gives the distances between cities along the highways, toget ...