• zoj 3633


    L - Alice's present
    Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu
    Submit Status

    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.

    噗。。

    想了半天都没想明白。。。

    一看市县5s。。要不就暴力来一发?

    虽然1.6s通过的。。。但总觉得哪里不对。。

    正解应该是线段树之类的吧?

    sad

    北京之前一定把基础线段树弄回了。。

    至少。。。

    抄几遍模板。。。

     1 /*************************************************************************
     2     > File Name: zoj/3633.cpp
     3     > Author: 111qqz
     4     > Email: rkz2013@126.com 
     5     > Created Time: 2015年10月22日 星期四 18时26分27秒
     6 ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<iomanip>
    10 #include<cstdio>
    11 #include<algorithm>
    12 #include<cmath>
    13 #include<cstring>
    14 #include<string>
    15 #include<map>
    16 #include<set>
    17 #include<queue>
    18 #include<vector>
    19 #include<stack>
    20 #include<cctype>
    21          
    22 #define yn hez111qqz
    23 #define j1 cute111qqz
    24 #define ms(a,x) memset(a,x,sizeof(a))
    25 using namespace std;
    26 const int dx4[4]={1,0,0,-1};
    27 const int dy4[4]={0,-1,1,0};
    28 typedef long long LL;
    29 typedef double DB;
    30 const int inf = 0x3f3f3f3f;
    31 const int N=5E5+7;
    32 int n,m;
    33 int a[N],ans[N];
    34 int l,r;
    35 set<int>se;
    36 
    37 
    38 
    39 int main()
    40 {
    41   #ifndef  ONLINE_JUDGE 
    42    freopen("in.txt","r",stdin);
    43   #endif
    44 
    45    while (scanf("%d",&n)!=EOF)
    46    {
    47     
    48 
    49        for ( int i = 1 ; i <= n ; i++) scanf("%d",&a[i]);
    50 
    51        scanf("%d",&m);
    52 
    53        for ( int i = 0 ; i < m ; i++)
    54        {
    55        bool ok = true;
    56        scanf("%d %d",&l,&r);
    57        se.clear();
    58 
    59        for ( int j = r ; j >= l ; j--)
    60         {
    61 //        cout<<"j:"<<j<<" a[j]:"<<a[j]<<endl;
    62         if (!se.count(a[j]))
    63         {
    64             se.insert(a[j]);
    65         }
    66         else
    67         {
    68             ok = false;
    69             printf("%d
    ",a[j]);
    70             break;
    71         }
    72         
    73         }
    74        if (ok) puts("OK");
    75        }
    76     puts("");
    77 
    78        
    79    }
    80   
    81    
    82  #ifndef ONLINE_JUDGE  
    83   fclose(stdin);
    84   #endif
    85     return 0;
    86 }
    View Code
  • 相关阅读:
    The Instruments Workflow
    About Instruments
    视频播放插件Video.js
    各大三方API
    Xib、AutoLayout等使用心得
    克隆示例
    接口类型的多重继承
    高级着色语言简介
    DirectX Box
    Direct3D初始化
  • 原文地址:https://www.cnblogs.com/111qqz/p/4902493.html
Copyright © 2020-2023  润新知