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 the integers ai , ... , aj.

  题目就是求区间范围内出现最高的频率是多少。

  用RMQ的话,统计某个数和这个之前的频率,然后询问的时候就是求两部分的最大值,第一部分是与x相同的数的个数,第二部分是第一个与x不同到y的部分,用RMQ求第二部分。

  然后无力吐槽自己,logN数组开小了,结果一直WA,真是够傻逼的。

代码如下:

// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月17日 星期五 17时11分45秒
// File Name : 3368.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; int dp[MaxN][];
int logN[MaxN]; //!!! void init(int N,int num[])
{
logN[]=-; for(int i=;i<=N;++i)
{
logN[i]=logN[i-]+((i&(i-))==);
dp[i][]=num[i];
} for(int j=;j<=logN[N];++j)
for(int i=;i+(<<j)-<=N;++i)
dp[i][j]=max(dp[i][j-],dp[i+(<<(j-))][j-]);
} int RMQ(int a,int b)
{
if(a>b)
return ; int k=logN[b-a+]; return max(dp[a][k],dp[b-(<<k)+][k]);
} int num[MaxN];
int rem[MaxN],wei[MaxN];
int N,Q; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int a,b; while(~scanf("%d",&N) && N)
{
scanf("%d",&Q); rem[]=; for(int i=;i<=N;++i)
scanf("%d",&num[i]); for(int i=;i<=N;++i)
if(num[i]==num[i-])
rem[i]=rem[i-]+;
else
rem[i]=; wei[N]=N; for(int i=N-;i>=;--i)
if(num[i]==num[i+])
wei[i]=wei[i+];
else
wei[i]=i; init(N,rem); while(Q--)
{
scanf("%d %d",&a,&b);
printf("%d\n",max(RMQ(wei[a]+,b),min(wei[a],b)-a+));
}
} return ;
}

(简单) POJ 3368 Frequent values,RMQ。的更多相关文章

  1. poj 3368 Frequent values(RMQ)

    /************************************************************ 题目: Frequent values(poj 3368) 链接: http ...

  2. POJ 3368 Frequent values RMQ ST算法/线段树

                                                         Frequent values Time Limit: 2000MS   Memory Lim ...

  3. POJ 3368 Frequent values(RMQ 求区间出现最多次数的数字的次数)

    题目链接:http://poj.org/problem? id=3368 Description You are given a sequence of n integers a1 , a2 , .. ...

  4. POJ 3368 Frequent values RMQ 训练指南 好题

    #include<cstdio> #include<cstring> ; const int inf=0x3f3f3f3f; inline int max(int x,int ...

  5. POJ 3368 Frequent values 【ST表RMQ 维护区间频率最大值】

    传送门:http://poj.org/problem?id=3368 Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total S ...

  6. POJ 3368 Frequent values (基础RMQ)

    Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14742   Accepted: 5354 ...

  7. poj 3368 Frequent values(段树)

    Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13516   Accepted: 4971 ...

  8. poj 3368 Frequent values(RMQ)

    题目:http://poj.org/problem?id=3368 题意:给定n个数,顺序为非下降,询问某个区间内的数出现最多的数的 出现次数.. 大白书上的 例题..算是RMQ变形了, 对 原数组重 ...

  9. [RMQ] [线段树] POJ 3368 Frequent Values

    一句话,多次查询区间的众数的次数 注意多组数据!!!! RMQ方法: 预处理 i 及其之前相同的数的个数 再倒着预处理出 i 到不是与 a[i] 相等的位置之前的一个位置, 查询时分成相同的一段和不同 ...

随机推荐

  1. Simple But Useful Samples About 'grep' Command(简单实用的grep 命令)

    Do the following: grep -rnw '/path/to/somewhere/' -e "pattern" -r or -R is recursive, -n i ...

  2. Java中Date和Calender类的使用方法

    查看文章     Java中Date和Calender类的使用方法 2009-10-04 20:49 Date和Calendar是Java类库里提供对时间进行处理的类,由于日期在商业逻辑的应用中占据着 ...

  3. 初识Selenium(二)

    ---------------------------------------------------------------------------------------------------- ...

  4. 正确使用#include和前置声明(forward declaration)

    http://blog.csdn.net/SpriteLW/article/details/965702

  5. 数据格式处理(数字,日期),java处理,jsp的fmt处理

    java 格式处理  public static String formatTosepara(float data) {DecimalFormat df = new DecimalFormat(&qu ...

  6. IDL 建立影像金字塔

    形成按目录放好的,类似于Google Map Tile的金字塔瓦片Jpg. 1: ; 2: pro tsplit 3: ; 读入Jpeg格式文件 4: szFile = 'e:\test.jpg'; ...

  7. heartbeat集群安装配置

    安装配置高可用集群需要注意:1.节点名称:集群每个节点的名称都得能互相解析 /etc/hosts hosts主机名的正反解析结果必须跟"uname -n"的结果保持一致2.时间必须 ...

  8. MFC添加背景图片三种方法

    方法一: 1.声明成员变量CBrush m_brush;2.在InitDialog中添加代码: ? CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP1);  //IDB_B ...

  9. ACL in 和 out 区别 (重要)

    acl中in和out的区别   in和out是相对的,比如: A(s0)-----(s0)B(s1)--------(s1)C   www.2cto.com   假设你现在想拒绝A访问C,并且假设要求 ...

  10. nginx及php版本号隐藏

    配置完一台服务器后,并不是就可以高枕无忧了,前不久刚刚爆发的PHP 5.3.9版本的漏洞也搞得人心惶惶,所以说经常关注安全公告并及时升级服务器也是必要的.一般来说,黑客攻击服务器的首要步骤就是收集信息 ...