Poj 3368 Frequent values】的更多相关文章

传送门:http://poj.org/problem?id=3368 Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 23016   Accepted: 8060 Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that,…
/************************************************************ 题目: Frequent values(poj 3368) 链接: http://poj.org/problem?id=3368 题意: 给出n个数和Q个询问(l,r),对于每个询问求出(l,r)之 间连续出现次数最多的次数 算法: RMQ 思路: 借助数组f[i].表示第i位前面有f[i]个相同的数.对于 每个区间(l,r).暴力求前面几个相同的数.然后在用RMQ 求后面…
Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14742   Accepted: 5354 Description You are given a sequence of n integersa1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries consi…
Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13516   Accepted: 4971 Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries cons…
                                                     Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15229   Accepted: 5550 Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In…
Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16537   Accepted: 5981 Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries consisting of indice…
题目链接:http://poj.org/problem? id=3368 Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries consisting of indices i and j (1 ≤ i ≤ j ≤ n). For each query, dete…
题目:http://poj.org/problem?id=3368 题意:给定n个数,顺序为非下降,询问某个区间内的数出现最多的数的 出现次数.. 大白书上的 例题..算是RMQ变形了, 对 原数组重新分段,并标记相同的个数为 该段的数值,然后RMQ... #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm>…
Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries consisting of indices i and j (1 ≤ i ≤ j ≤ n). For each query, determine the most frequent value among t…
[题目链接] http://poj.org/problem?id=3368 [题目大意] 有一个有序序列,要求区间查询出现次数最多的数 [题解] 维护每个区间左端点和右端点,以及左右的长度,还有区间的答案 每次线段合并的时候,对区间数据进行合并即可. [代码] #include <cstdio> #include <algorithm> using namespace std; const int N=100010; struct data{int a,b,l,r,val;}T[N…
题目链接:http://poj.org/problem?id=3368 题目意思:给出一段 n 个数的序列你,对于区间 [l, r] 的询问,找出 出现频率最高的数的次数.考虑到序列中的数是非递减的,也就是相同的数会连续不间断地在一起,于是就才有了代码中这个部分来预判了: if (s > t)        printf("%d\n", ans); 这个人写RMQ 写得不错:http://dongxicheng.org/structure/lca-rmq/ 这题就是套模板的,纪念…
#include<cstdio> #include<cstring> ; const int inf=0x3f3f3f3f; inline int max(int x,int y) { return x>y?x:y; } int a[maxn]; int left[maxn]; int right[maxn]; int num[maxn]; ]; void init() { memset(a,,sizeof a); memset(left,-,sizeof left); me…
一句话,多次查询区间的众数的次数 注意多组数据!!!! RMQ方法: 预处理 i 及其之前相同的数的个数 再倒着预处理出 i 到不是与 a[i] 相等的位置之前的一个位置, 查询时分成相同的一段和不同的一段 (RMQ) 但是要注意 to[i] 大于查询范围的情况, 以及RMQ时 x < y 的情况!! AC代码: #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib>…
/* 线段树区间合并 维护几个信息 到时候乱搞一下就好了 开始T了 有一种情况可以不用递归 直接算出来 */ #include<iostream> #include<cstdio> #include<cstring> #define maxn 100010 #define lc (k<<1) #define rc (k<<1)+1 #define mid ((l+r)>>1) using namespace std; ],rs[max…
<题目链接> 题目大意: 给你一个长度为n的序列,这个序列每个数都有一个值,接下来进行q次询问,问在指定区间内出现次数最多的数出现了几次. 解题分析: 因为该序列是非降序的,所以该序列中的所有相等的数都是连续的,因此,我们可以先用dp预处理一下,dp[i]表示以第i个数结尾的最大连续相等个数,于是,本题目就变成了,在指定区间内,dp[i]的最大的值是多少. #include <cstdio> #include <cstring> #include <cmath&g…
题意:给出n个数的非递减序列,进行q次查询.每次查询给出两个数a,b,求出第a个数到第b个数之间数字的最大频数. 如序列:-1 -1 1 1 1 1 2 2 3 第2个数到第5个数之间出现次数最多的是数字1,它的频数3. 思路:假设查询时的参数为a, b.这道题查询时有以下两种情况: 1. num[a] = num[b]. 即区间内的数字全相同,此时答案为b - a + 1. 2. 如果不相同,则以一般情况来讨论.见下图. 因为序列为非递减序列,因此值相同的数字必然连续出现.将区间分为3部分.n…
昨天写的博客删了,占坑失败,还是先把RMQ玩的6一点再去搞后面的东西.废话少说,题解题姐姐_(:з」∠)_      Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20960   Accepted: 7403 Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing ord…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1806 题目大意:给你一个非降序排列的整数数组,你的任务是对于一系列的询问,(i,j),回答序列中出现次数最多的数的个数: 如下图所示: AC代码: #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<queue> #include<…
2007/2008 ACM International Collegiate Programming Contest University of Ulm Local Contest Problem F: Frequent values You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several querie…
Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14764   Accepted: 5361 Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries cons…
Frequent values 题意是不同颜色区间首尾相接,询问一个区间内同色区间的最长长度. 网上流行的做法,包括翻出来之前POJ的代码也是RMQ做法,对于序列上的每个数,记录该数向左和向右延续的最远位置,那么对于一个查询Q(L, R),它的答案就分成了三种情况right(L) - L,R - left(R)以及Q(L+right(L),R-left(R)). 这里给出一个线段树做法,在线段树的节点上维护3个量:l_value, r_value, value分别表示以左端点为起始点,以右端点为…
2007/2008 ACM International Collegiate Programming Contest University of Ulm Local Contest Problem F: Frequent values You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several querie…
Problem F: Frequent values You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries consisting of indices i and j (1 ≤ i ≤ j ≤ n). For each query, determine the most frequen…
UVa 11235 Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11241   Accepted: 4110 Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several qu…
Frequent values Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1146    Accepted Submission(s): 415 Problem Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasin…
Frequent values You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries consisting of indices i and j (1 ≤ i ≤ j ≤ n). For each query, determine the most frequent value amo…
一直感觉RMQ水,没自己写过,今天写了一道题,算是完全独立写的,这感觉好久没有了... 一直以来,都是为了亚洲赛学算法,出现了几个问题: 1.学的其实只是怎么用算法,对算法的正确性没有好好理解,或者说根本没有真的理解算法并从这个算法在做修改延伸: 2.学的很不系统,没有好好对比整理各种题型,更别说好好总结: 3.貌似整天参考别人代码,很少独立做题: 操,这种急功近利的学习方式终于可以在亚洲赛没机会现场赛的时候结束了,想来也是好事 不废话了,入正题 一.RMQ原理 DP思想:dp(i,j)=min…
Frequent values TimeLimit:3000Ms , ... , an in non-decreasing order. In addition to that, you are given several queries consisting of indices i and j (1 ≤ i ≤ j ≤ n). For each query, determine the most frequent value among the integers ai , ... , aj.…
D. Frequent values Time Limit: 3000ms Case Time Limit: 3000ms Memory Limit: 131072KB   64-bit integer IO format: %lld      Java class name: Main   2007/2008 ACM International Collegiate Programming Contest University of Ulm Local Contest Problem F: F…
RMQ算法 简单来说,RMQ算法是给定一组数据,求取区间[l,r]内的最大或最小值. 例如一组任意数据 5 6 8 1 3 11 45 78 59 66 4,求取区间(1,8)  内的最大值.数据量小时,只需遍历一遍就可以,数据量一大时就容易时间超限,RMQ算法是一种高效算法,和线段树差不多(当没有数据的实时更新时),当然两者都需要预处理. 定义映射f(i,j)=x,即以i为起点,长度为2j 区间内的最大最小值,显而易见f(i,0)为该数本身,那么求f(i,j+1)时: 可得公式 f(i,j)=…