hdu 5172 GTY's gay friends】的更多相关文章

GTY's gay friends 题意:给n个数和m次查询:(1<n,m<1000,000);之后输入n个数值(1 <= ai <= n):问下面m次查询[L,R]中是否存在1~R-L+1的序列: 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   分析:问区间是否存在1~R-L+1的排列:注意里面没…
GTY's gay friends Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) [Problem Description] GTY has n gay friends. To manage them conveniently, every morning he ordered all his gay friends to stand in a line. Every gay…
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5172 bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=567&pid=1003 题解: 线段树+前缀和 一个区间要满足1到n的一个排列,要同时满足两点,一是它的和是n*(n+1)/2,这个可以用前缀和直接求:二是它每个元素不能重复. 区间内每个元素都不能重复: 记录第i个元素的左边一个离…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5172 题意: 给你一个n个数的数组,m次询问,询问在[L, R] 这个区间里面有没有 [1, R-L+1] 的数. 题解: 判断有没有 1 ~ R-L+1 其实就是判断这一段区间和是不是等于 (R-L+1)*(R-L+1+1)/ 2 . 当然还有就是每一个数只能出现1次. 这个问题我们应该怎么解决呢. 我们可以记录第i个数x 的前一个x出现的位置.如果x的前一个x也出现在[L, R]里面,那么这一段…
题意: GTY有n个朋友,站成一排,每个人有一个特征值ai. 有m个询问.每次询问给两个数L,R.问你[L,R](即aL...aR)是否是1..(R-L+1)的一个全排列. 是输出YES,否则输出NO 思路: 先判断是否segma(a[L,R])是否等于(R-L)*(R-L+1)/2. 记录每一个ai上一次的位置pre[i]. 这样只要判断a[L]...a[R]中的每一个pre[i]是否都小于L即可.(这个方法太妙) 线段树区间求最大值. *用map效率明显下降. 代码: int const N…
传送门 GTY's gay friends Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 264    Accepted Submission(s): 57 Problem Description GTY has n gay friends. To manage them conveniently, every morning he o…
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 answe…
GTY's gay friends Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1379    Accepted Submission(s): 355 Problem Description GTY has n gay friends. To manage them conveniently, every morning he ord…
GTY's birthday gift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)  [Problem Description] FFZ's birthday is coming. GTY wants to give a gift to ZZF. He asked his gay friends what he should give to ZZF. One of them…
http://acm.hdu.edu.cn/showproblem.php?pid=5172 判断一个区间是否为全排列是: 1.区间总和 = (1 + R - L + 1) * (R - L + 1) / 2; 2.区间没有重复数字 记录数组a[i]表示第i个数上一次在那个位置出现. 那么最需要在[L, R]中a[i]的最大值 >= L的,就是有重复数字了. #include <bits/stdc++.h> #define IOS ios::sync_with_stdio(false)…