ZOJ-3633-Alice's present
2015-10-08 13:54
351 查看
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.
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
Sample Output
简单的数学题
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.
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.简单的数学题
#include <iostream> #include <cstdio> #include <map> #include <cmath> using namespace std; int main() { int n; int arr[500005]; map<int,int> m1; while(cin>>n) { for(int i=0;i<n;++i) cin>>arr[i]; int m; cin>>m; // cout<<m<<endl; for(int i=0;i<m;++i) { // cout<<"sdf"<<endl; int l,r,res=-1; cin>>l>>r; m1.clear(); for(int i=r-1;i>=l-1;--i) { m1[arr[i]]++; if(m1[arr[i]]>1) { res=arr[i]; break; } } // cout<<res<<endl; if(res==-1) cout<<"OK"<<endl; else cout<<res<<endl; } cout<<"\n"; } return 0; }
相关文章推荐
- js控制5秒后页面自动跳转
- angular.js基础—服务(service)及其调用
- 论c程序员转java学习
- 简单理解js面向对象工厂方式
- 转 GRE -- ME 似乎有件事,一直等待着我去做,努力去做。
- 手机号码归属地接口开发文档及调用实例
- 如何导入support_V4包中源码
- iOS退出键盘方法
- 嵌入式C语言中的Doxygen注释模板
- /persistence.cpp:5008: error: (-2) The node does not represent a user object (unknown type?) in func
- mac grep: /usr/include/php/main/php.h: No such file or directory
- Windows 10 windows update失败,无法更新补丁
- likely() and unlikely()
- SQl格式化日期时间
- 网络连接评分机制之NetworkFactory(原)
- bzoj-2797 Squarks
- bnuoj 24250 Binary Operations (概率DP)
- Forbidden You don't have permission to access / on this server.解决方法
- 【jQuery】2.jquery基础知识2
- Android 中的DisplayMetrics类的用法