ZOJ Monthly, August 2012 - A Alice's present MAP函数
2012-08-26 20:23
218 查看
Alice's present
Time Limit: 5 Seconds
Memory Limit: 65536 KB
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 ton. Each time Alice chooses an interval from
i to j in the sequence ( includei 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 .
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 intergerm ( 1 ≤
m ≤ 50,000 ),indicate how many intervals Alice will query. Then followed by m lines, each line contains two integeru,
v ( 1≤ u< v≤ n ),indicate the left endpoint and right endpoint of the interval.Process to the end of input.
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.
题意:
输入n个数 在输入m个询问区间 问区间内从右向左看有没有重复的数字 如果有 输出第一个重复的 如果没有 输出OK
思路:对每个区间进行访问 利用map函数的一对一 的性质 利用其find函数 看是否有的已经存在 如果不存在 则把 该数 和1 添加进map()
如果找到了就说明重复了 直接输出该数即可
Time Limit: 5 Seconds
Memory Limit: 65536 KB
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 ton. Each time Alice chooses an interval from
i to j in the sequence ( includei 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 intergerm ( 1 ≤
m ≤ 50,000 ),indicate how many intervals Alice will query. Then followed by m lines, each line contains two integeru,
v ( 1≤ u< v≤ n ),indicate the left endpoint and right endpoint of the interval.Process to the end of input.
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
Alice will check each interval from right to left, don't make mistakes.题意:
输入n个数 在输入m个询问区间 问区间内从右向左看有没有重复的数字 如果有 输出第一个重复的 如果没有 输出OK
思路:对每个区间进行访问 利用map函数的一对一 的性质 利用其find函数 看是否有的已经存在 如果不存在 则把 该数 和1 添加进map()
如果找到了就说明重复了 直接输出该数即可
#include<stdio.h> #include<map> #include<cstring> using namespace std; int a[500500]; map<int,int>mp; int main() { int n,i,m,left,right; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) scanf("%d",&a[i]); scanf("%d",&m); while(m--) { scanf("%d%d",&left,&right); mp.clear(); for(i=right;i>=left;i--) { if(mp.find(a[i])==mp.end()) mp[a[i]]=1; else {break;} } if(i==left-1) printf("OK\n"); else printf("%d\n",a[i]); } printf("\n"); } return 0; }
相关文章推荐
- ZOJ Monthly, August 2012-A-ZOJ 3633 ZOJ 3635
- ZOJ Monthly, August 2012
- ZOJ Monthly, August 2012
- ZOJ Monthly, August 2012 题解
- ZOJ Monthly, August 2012 - C Cinema in Akiba 树状数组+二分
- ZOJ Monthly, August 2012部分题目总结
- zoj 3805 Machine(ZOJ Monthly, August 2014 - H)
- ZOJ Monthly, August 2011 zoj 3528
- zoj Monthly, February 2012 - D Under Attack II (zoj 3574)
- ZOJ Monthly, June 2012 - B Median - zoj 3612
- Adobe Acrobat X Standard coupon code for you on 2012 August 4th
- OpenGL 4.3 (Core Profile) - August 6, 2012 spec Fundamental 2.3 Command Execution
- OpenGL 4.3 (Core Profile) - August 6, 2012 spec Fundamental 2.5 Objects and the Object Model
- ZOJ Monthly, August 2011 zoj 3520
- ZOJ Monthly, November 2012 慎入
- zoj 3804 YY's Minions (ZOJ Monthly, August 2014 - G)
- ZOJ Monthly, June 2012 - K Factorial Problem in Base K - zoj 3621
- ZOJ Monthly,Feburary 2012 部分题解
- OpenGL 4.3 (Core Profile) - August 6, 2012 spec Fundamental 3 Dataflow Model
- ZOJ Monthly, August 2011 zoj 3523