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< vn ),indicate the left endpoint and right endpoint of the interval. Process to the end of input.

,C​i​​,即此题的初始分值、每分钟减少的分值、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

  1. 5
  2. 1 2 3 1 2
  3. 3
  4. 1 4
  5. 1 5
  6. 3 5
  7. 6
  8. 1 2 3 3 2 1
  9. 4
  10. 1 4
  11. 2 5
  12. 3 6
  13. 4 6

Sample Output

  1. 1
  2. 2
  3. OK
  4.  
  5. 3
  6. 3
  7. 3
  8. OK

HINT

题意

查询一个区间是否有重复,以及从右边开始,第一个重复的数是什么

题解:

直接记录pre就好了

然后st区间查询最大值就好了

代码:

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<map>
  5. using namespace std;
  6. #define maxn 500500
  7. int a[];
  8. int dp[maxn][];
  9. int mm[maxn];
  10. int val[maxn];
  11. void initrmp(int n)
  12. {
  13. mm[]=-;
  14. for(int i=;i<=n;i++)
  15. {
  16. mm[i]=((i&(i-))==)?mm[i-]+:mm[i-];
  17. dp[i][]=val[i];
  18. }
  19. for(int j = ;j<=mm[n];j++)
  20. for(int i=;i+(<<j)-<=n;i++)
  21. dp[i][j]=max(dp[i][j-],dp[i+(<<(j-))][j-]);
  22. }
  23. int query(int l,int r)
  24. {
  25. int k = mm[r-l+];
  26. return max(dp[l][k],dp[r-(<<k)+][k]);
  27. }
  28. map<int,int> H;
  29. int main()
  30. {
  31. int n;
  32. while(scanf("%d",&n)!=EOF)
  33. {
  34. memset(mm,,sizeof(mm));
  35. memset(val,,sizeof(val));
  36. memset(dp,,sizeof(dp));
  37. memset(a,,sizeof(a));
  38. H.clear();
  39. //int n;scanf("%d",&n);
  40. for(int i=;i<=n;i++)
  41. scanf("%d",&a[i]);
  42. for(int i=;i<=n;i++)
  43. {
  44. val[i]=H[a[i]];
  45. H[a[i]]=i;
  46. }
  47. initrmp(n);
  48. int m;scanf("%d",&m);
  49. while(m--)
  50. {
  51. int l ,r;
  52. scanf("%d%d",&l,&r);
  53. int p = query(l,r);
  54. if(p<l)printf("OK\n");
  55. else printf("%d\n",a[p]);
  56. }
  57. printf("\n");
  58. }
  59. }

ZOJ 3633 Alice's present 倍增 区间查询最大值的更多相关文章

  1. 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 ...

  2. vijos 1659 河蟹王国 线段树区间加、区间查询最大值

    河蟹王国 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 https://vijos.org/p/1659 Description 河蟹王国有一位河蟹国王,他 ...

  3. ACM_3n+1问题(克拉兹问题+线段树区间查询最大值)

    3n+1问题 Time Limit: 2000/1000ms (Java/Others) Problem Description: 考虑如下的序列生成算法:从整数n开始,如果n是偶数,把它除以2:如果 ...

  4. ZOJ 3757 Alice and Bob and Cue Sports(模拟)

    题目链接 题意 : 玩台球.Alice 和 Bob,一共可以进行m次,Alice 先打.有一个白球和n个标有不同标号的球,称目标球为当前在桌子上的除了白球以外的数值最小的球,默认白球的标号为0.如果白 ...

  5. HDU 4791 &amp; ZOJ 3726 Alice&#39;s Print Service (数学 打表)

    题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...

  6. hdu5289 Assignment (区间查询最大值最小值,st算法...)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5289 题意:给定长度为n的序列a和一个整数K,找出最大值和最小值的差值小于K的区间.输出满足条件的区间的个 ...

  7. zoj 3757 Alice and Bob and Cue Sports 模拟

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3757 #include<cstdio> #incl ...

  8. zoj 3757 Alice and Bob and Cue Sports 月赛A 模拟

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3757 题意:根据所给的台球规则,按照每次的结果计算最终两人的得分 ...

  9. ZOJ 3203 Light Bulb - 求导求最大值

    如果L全在地面上: 输出 h * D / H 如果L全在墙上: 输出 h 否则: (D - X ) / X = Y / (H - h) L = D - X + h - Y 然后对L求导即可 #incl ...

随机推荐

  1. POJ 1811 Prime Test

    题意:对于一个大整数,判断是否质数,如果不是质数输出最小质因子. 解法:判断质数使用Miller-Rabin测试,分解质因子使用Pollard-Rho,Miller-Rabin测试用的红书模板,将测试 ...

  2. linux命令——磁盘管理cd

    Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的. cd指令可让用户在不同的目录间切换,但该用户必须拥有足够的权限进入目的目录. 1 ...

  3. android studio SDK版本的调节

    android { compileSdkVersion 17 buildToolsVersion "17.0.0" defaultConfig { minSdkVersion 17 ...

  4. Selenium IDE测试创建

    Selenium IDE 测试创建 涉及使用IDE Selenium创建测试,如下面的步骤 记录和测试添加命令 保存测试记录 保存测试程序 执行测试记录 在测试中记录和添加命令 为了演示目的,我们将利 ...

  5. duilib combo控件,当鼠标滚动时下拉列表自动关闭的bug的修复

    转载请说明出处,谢谢~~ 群里有朋友提到了使用Combo控件时,当下拉列表出现,此时鼠标滚轮滚动,下拉列表就自动消失了.我看了一下源码,这个bug的修复很简单. CComboUI控件被单击时创建CCo ...

  6. CSS基础知识——选择器

    选择器 元素选择器# 文档元素为最基本的选择器 例子:div{属性:值}; 选择器分组 例子:h2,p{属性:值}; 表示符合这两种规则的元素设置相同的属性值 通配选择器 表示所有元素 类选择器 应用 ...

  7. [转]天龙八部服务器端Lua脚本系统

    一.Lua脚本功能接口 1. LuaInterface.h/.cpp声明和实现LuaInterface. LuaInterface成员如下: //脚本引擎 FoxLuaScriptmLua ; //注 ...

  8. Windows下GNU之gcc体验方法

    Windows 现在在Windows下开发C/C++程序一般都是用微软的编译器,当年的Borland已经成为传说.但是如果你不想付钱的话,也可以考虑Windows下的GCC. 在Windows下体验G ...

  9. hadoop测试环境主配置简例

    1,mapred-site.xml 此配置文件主要是针对mapreduce的配置文件,配置的是jobtracker的地址和端口; <configuration> <property& ...

  10. 转】Maven学习总结(四)——Maven核心概念

    原博文出自于: http://www.cnblogs.com/xdp-gacl/p/4051819.html 感谢! 一.Maven坐标 1.1.什么是坐标? 在平面几何中坐标(x,y)可以标识平面中 ...