码迷,mamicode.com
首页 > 其他好文 > 详细

(map) zoj 1633

时间:2015-01-30 17:07:27      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

A - Alice‘s present
Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu
Appoint description: 

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 jin 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 integeruv ( 1≤ uv≤ 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<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<map>
using namespace std;
map<int,int> mp;
#define N 500010
int n,num[N],m;
int main()
{
      int x,y;
      while(scanf("%d",&n)!=EOF)
      {
            int pos;
            for(int i=1;i<=n;i++)
                  scanf("%d",&num[i]);
            scanf("%d",&m);
            while(m--)
            {
                 bool flag=false;
                 mp.clear();
                 scanf("%d%d",&x,&y);
                 for(int i=y;i>=x;i--)
                 {
                       if(!mp.count(num[i]))
                       {
                             mp[num[i]]=1;
                       }
                       else
                       {
                             pos=i;
                             flag=true;
                             break;
                       }
                 }
                 if(!flag)
                 {
                       printf("OK\n");
                 }
                 else
                 {
                       printf("%d\n",num[pos]);
                 }
            }
            printf("\n");
      }
      return 0;
}

  

(map) zoj 1633

标签:

原文地址:http://www.cnblogs.com/a972290869/p/4262409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!