poj3368 uva11235 Frequent values】的更多相关文章

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…
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…
题目大意:在一个长度为n的不降序列中,有m次询问,每次询问(i,j)表示在区间(i,j)中找出出现次数最多的元素的出现次数. 题目分析:因为序列有序,可以将序列分段,并且记录每段的元素个数.每一个元素所属的段num(i).每一个元素所属段的左端点l(i)及右端点r(i).那么对于每次询问: ans(i,j)=max(max(r(i)-i+1,j-l(j)+1),rmq(num(i)+1,num(j)-1)). ans(i,j)=r-j+1 (如果i与j属于同一段) 代码如下: # include…
思路 连续的值只会分布在一起成一个块 讨论两边的块,中间就是RMQ了 ST表即可 代码 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int times[100100],belong[100100],lb[100100],rb[100100],inq,n,q,st[100100][21]; void init_ST(void){ for(int i=1;i&l…
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(poj 3368) 链接: http://poj.org/problem?id=3368 题意: 给出n个数和Q个询问(l,r),对于每个询问求出(l,r)之 间连续出现次数最多的次数 算法: RMQ 思路: 借助数组f[i].表示第i位前面有f[i]个相同的数.对于 每个区间(l,r).暴力求前面几个相同的数.然后在用RMQ 求后面…
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…
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分别表示以左端点为起始点,以右端点为…
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…
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: 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 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.…
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…
传送门: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,…
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…
                                                     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…
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)=…
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…
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…
题目大概说给一个递增序列,询问区间出现最多的数. 用莫队算法比较直观,虽然应该会T..好像也可以主席树..不过题目给的序列是有序的,因而相同的数会聚在一起. 考虑把序列分成一段一段,使每段都包含极大的相同的数字 这样对于每一个区间查询: 可能这个区间左边或右边没有包含完整的一段,而其长度在段里对左或右端点进行二分查找就知道了 而除去两边不完整的,还要求出中间若干完整段的最大长度,这个就是用RMQ来快速解决了 于是这题就能这样解决了. #include<cstdio> #include<c…
题意:给出n个数和Q个询问(l,r),对于每个询问求出(l,r)之间连续出现次数最多的次数. 解题关键:统计次数,转化为RMQ问题,运用st表求解,注意边界. 预处理复杂度:$O(n\log n)$ #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<cmath> #include<iostream> using names…
思路: 转化为RMQ. 实现: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; const int INF = 0x3f3f3f3f; ], n, m, sum[MAXN]; void build(int num, int l, int r) { if (l == r) { tree[num] = a[l]; return; } ; build(num *…
题目在这里 3368 Accepted 7312K 1829MS C++ 6936B 题意为给你一组数据,再给定一组区间,问你这个区间内出现次数最多的元素的次数是多少. 我还记得这题是学校校赛基础的题目,当时懵懵懂懂的用分治交了6次TLE.知道了线段树之后才后悔每更早的认识她. 一段区间内的多次出现的数的次数,在线段树查询中有以下几种情况 1.次数最多的都集中在某一结点的左区间内 2.次数最多的都集中在某一结点的有区间内 3.次数最多的在左右两边都有,这时maxCount ==左右两边的maxC…
poj3368:http://poj.org/problem?id=3368 题意:给你一个非下降的序列,然后查询[l,r]内出现最多数字的次数. 题解:首先,因为序列是非下降的,所以相同的数字出现在在一起.所以,可以定义一个数组a[i]=k,表示第i个数出现的次数,另外还要记录几个东西,ll[i],rr[i],分别表示第i个数首次出现的位置和最后出现的位置.sum[i]到第i数出现结束之后一共有多少个数.准备好了这些东西之后.既可以开始了.第一步以数的个数(相同的算一个)建立线段树,叶子节点的…
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…
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…
一.题面 POJ3368 二.分析 仍然是一道只需要区间查询不需要区间修改的线段树题. 这题的题面比较特别,它是一组非减的数组.当需要去找一段区间内出现次数最多的数字时,这些数字必然是连续的,那么就可以用线段树维护区间内出现的最大次数时,同时维护两端的数字出现的次数.这样,就可以在建树的时候通过判断可能的左右子树最大值和(左子树的最右端的数的次数+右子树的最左端的数的次数),括号出现的前提是左子树维护的区间右端点的数与右子树维护的区间左端点的数相等. 保证建树建成功后,就是基本的查询了,但是需要…
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…
描述 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 the intege…