ZOJ 3633 Alice's present 倍增 区间查询最大值
Alice's present
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=95030#problem/A
Description
As a doll master, Alice owns a wide range of dolls, and each of them has a number tip on it's back, the tip can be treated as a positive integer. (the number can be repeated). One day, Alice hears that her best friend Marisa's birthday is coming , so she decides to sent Marisa some dolls for present. Alice puts her dolls in a row and marks them from 1 to n. Each time Alice chooses an interval from i to j in the sequence ( include i and j ) , and then checks the number tips on dolls in the interval from right to left. If any number appears more than once , Alice will treat this interval as unsuitable. Otherwise, this interval will be treated as suitable.
This work is so boring and it will waste Alice a lot of time. So Alice asks you for help .
Input
There are multiple test cases. For each test case:
The first line contains an integer n ( 3≤ n ≤ 500,000) ,indicate the number of dolls which Alice owns.
The second line contains n positive integers , decribe the number tips on dolls. All of them are less than 2^31-1. The third line contains an interger m ( 1 ≤ m ≤ 50,000 ),indicate how many intervals Alice will query. Then followed by m lines, each line contains two integer u, v ( 1≤ u< v≤ n ),indicate the left endpoint and right endpoint of the interval. Process to the end of input.
,Ci,即此题的初始分值、每分钟减少的分值、dxy做这道题需要花费的时间。
Output
For each test case:
For each query, If this interval is suitable , print one line "OK". Otherwise, print one line ,the integer which appears more than once first.
Print an blank line after each case.
Sample Input
- 5
- 1 2 3 1 2
- 3
- 1 4
- 1 5
- 3 5
- 6
- 1 2 3 3 2 1
- 4
- 1 4
- 2 5
- 3 6
- 4 6
Sample Output
- 1
- 2
- OK
- 3
- 3
- 3
- OK
HINT
题意
查询一个区间是否有重复,以及从右边开始,第一个重复的数是什么
题解:
直接记录pre就好了
然后st区间查询最大值就好了
代码:
- #include<stdio.h>
- #include<iostream>
- #include<cstring>
- #include<map>
- using namespace std;
- #define maxn 500500
- int a[];
- int dp[maxn][];
- int mm[maxn];
- int val[maxn];
- void initrmp(int n)
- {
- mm[]=-;
- for(int i=;i<=n;i++)
- {
- mm[i]=((i&(i-))==)?mm[i-]+:mm[i-];
- dp[i][]=val[i];
- }
- for(int j = ;j<=mm[n];j++)
- for(int i=;i+(<<j)-<=n;i++)
- dp[i][j]=max(dp[i][j-],dp[i+(<<(j-))][j-]);
- }
- int query(int l,int r)
- {
- int k = mm[r-l+];
- return max(dp[l][k],dp[r-(<<k)+][k]);
- }
- map<int,int> H;
- int main()
- {
- int n;
- while(scanf("%d",&n)!=EOF)
- {
- memset(mm,,sizeof(mm));
- memset(val,,sizeof(val));
- memset(dp,,sizeof(dp));
- memset(a,,sizeof(a));
- H.clear();
- //int n;scanf("%d",&n);
- for(int i=;i<=n;i++)
- scanf("%d",&a[i]);
- for(int i=;i<=n;i++)
- {
- val[i]=H[a[i]];
- H[a[i]]=i;
- }
- initrmp(n);
- int m;scanf("%d",&m);
- while(m--)
- {
- int l ,r;
- scanf("%d%d",&l,&r);
- int p = query(l,r);
- if(p<l)printf("OK\n");
- else printf("%d\n",a[p]);
- }
- printf("\n");
- }
- }
ZOJ 3633 Alice's present 倍增 区间查询最大值的更多相关文章
- ZOJ 3633 Alice's present RMQ
Alice's present Description As a doll master, Alice owns a wide range of dolls, and each of them ha ...
- vijos 1659 河蟹王国 线段树区间加、区间查询最大值
河蟹王国 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 https://vijos.org/p/1659 Description 河蟹王国有一位河蟹国王,他 ...
- ACM_3n+1问题(克拉兹问题+线段树区间查询最大值)
3n+1问题 Time Limit: 2000/1000ms (Java/Others) Problem Description: 考虑如下的序列生成算法:从整数n开始,如果n是偶数,把它除以2:如果 ...
- ZOJ 3757 Alice and Bob and Cue Sports(模拟)
题目链接 题意 : 玩台球.Alice 和 Bob,一共可以进行m次,Alice 先打.有一个白球和n个标有不同标号的球,称目标球为当前在桌子上的除了白球以外的数值最小的球,默认白球的标号为0.如果白 ...
- HDU 4791 & ZOJ 3726 Alice's Print Service (数学 打表)
题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...
- hdu5289 Assignment (区间查询最大值最小值,st算法...)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5289 题意:给定长度为n的序列a和一个整数K,找出最大值和最小值的差值小于K的区间.输出满足条件的区间的个 ...
- zoj 3757 Alice and Bob and Cue Sports 模拟
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3757 #include<cstdio> #incl ...
- zoj 3757 Alice and Bob and Cue Sports 月赛A 模拟
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3757 题意:根据所给的台球规则,按照每次的结果计算最终两人的得分 ...
- ZOJ 3203 Light Bulb - 求导求最大值
如果L全在地面上: 输出 h * D / H 如果L全在墙上: 输出 h 否则: (D - X ) / X = Y / (H - h) L = D - X + h - Y 然后对L求导即可 #incl ...
随机推荐
- POJ 1811 Prime Test
题意:对于一个大整数,判断是否质数,如果不是质数输出最小质因子. 解法:判断质数使用Miller-Rabin测试,分解质因子使用Pollard-Rho,Miller-Rabin测试用的红书模板,将测试 ...
- linux命令——磁盘管理cd
Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的. cd指令可让用户在不同的目录间切换,但该用户必须拥有足够的权限进入目的目录. 1 ...
- android studio SDK版本的调节
android { compileSdkVersion 17 buildToolsVersion "17.0.0" defaultConfig { minSdkVersion 17 ...
- Selenium IDE测试创建
Selenium IDE 测试创建 涉及使用IDE Selenium创建测试,如下面的步骤 记录和测试添加命令 保存测试记录 保存测试程序 执行测试记录 在测试中记录和添加命令 为了演示目的,我们将利 ...
- duilib combo控件,当鼠标滚动时下拉列表自动关闭的bug的修复
转载请说明出处,谢谢~~ 群里有朋友提到了使用Combo控件时,当下拉列表出现,此时鼠标滚轮滚动,下拉列表就自动消失了.我看了一下源码,这个bug的修复很简单. CComboUI控件被单击时创建CCo ...
- CSS基础知识——选择器
选择器 元素选择器# 文档元素为最基本的选择器 例子:div{属性:值}; 选择器分组 例子:h2,p{属性:值}; 表示符合这两种规则的元素设置相同的属性值 通配选择器 表示所有元素 类选择器 应用 ...
- [转]天龙八部服务器端Lua脚本系统
一.Lua脚本功能接口 1. LuaInterface.h/.cpp声明和实现LuaInterface. LuaInterface成员如下: //脚本引擎 FoxLuaScriptmLua ; //注 ...
- Windows下GNU之gcc体验方法
Windows 现在在Windows下开发C/C++程序一般都是用微软的编译器,当年的Borland已经成为传说.但是如果你不想付钱的话,也可以考虑Windows下的GCC. 在Windows下体验G ...
- hadoop测试环境主配置简例
1,mapred-site.xml 此配置文件主要是针对mapreduce的配置文件,配置的是jobtracker的地址和端口; <configuration> <property& ...
- 转】Maven学习总结(四)——Maven核心概念
原博文出自于: http://www.cnblogs.com/xdp-gacl/p/4051819.html 感谢! 一.Maven坐标 1.1.什么是坐标? 在平面几何中坐标(x,y)可以标识平面中 ...