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. 清除number输入框的上下箭头

    <input type="number"/> 在chrome,firefox,safari浏览器上输入框右侧会有上下箭头 方法1: <input type=&qu ...

  2. sqlserver日志文件过大的处理方法

      SqlServer 数据库中与备份和恢复相关的日志文件有MDF和LDF文件 存在于\\sqlserver_install_dir\MSSQL\Data\1.文件解释.mdf文件    MDF是SQ ...

  3. ignite客户端找不到服务端的时候如何设置退出

    ignite启动客户端时需要有服务端支持: Ignition.setClientMode(true); Ignition.start("ignite.xml"); 这里有个问题,当 ...

  4. CodeForces 719A Vitya in the Countryside 思维题

    题目大意:月亮从0到15,15下面是0.循环往复.给出n个数字,如果下一个数字大于第n个数字输出UP,小于输出DOWN,无法确定输出-1. 题目思路:给出0则一定是UP,给出15一定是DOWN,给出其 ...

  5. 【转】linux grep命令详解

    简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它 ...

  6. DEAMONTOOLS: installation

    installing daemontools .. adding -I /usr/include/errno.h to last first line of conf-cc mkdir -p /pac ...

  7. 初探JavaScript魅力

    <style> #div1{width:200px; height:200px; background:red;} </style> </head> <scr ...

  8. lucene-SpanNotQuery和SpanOrQuery交迭与全局跨度

    1.在匹配结果中排除相互交迭的跨度 SpanNotQuery构造函数的第一个参数表示要包含的跨度对象,第二个参数表示要排除的跨度对象. 1) SpanNearQuery quick_fox=new S ...

  9. CSS3简介

    选择器 盒模型 背景和边框 文字特效 2d/3d转换 动画 多列布局 用户界面

  10. Node.js学习 - Web Server

    Client - 客户端,一般指浏览器,浏览器可以通过 HTTP 协议向服务器请求数据. Server - 服务端,一般指 Web 服务器,可以接收客户端请求,并向客户端发送响应数据. Busines ...