记录编号 360314 评测结果 AAAAAAAAAAAAAAA
题目名称 [POI 2014] 快递员 最终得分 100
用户昵称 Gravatarsxysxy 是否通过 通过
代码语言 C++ 运行时间 3.750 s
提交时间 2016-12-29 07:25:07 内存使用 27.26 MiB
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#include <cctype>
using namespace std;
namespace IO
{
char buf[1<<18], *fs, *ft;
inline char readc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<18,stdin),fs==ft))?0:*fs++;
}
inline int fast_read()
{
    int r;
    char c;
    bool s = false;
    while(c = readc())
    {
        if(c >= '0' && c <= '9')
        {
            r = c^0x30;
            break;
        }else if(c == '-')s = true;
    }
    while(isdigit(c = readc()))
        r = (r<<3)+(r<<1)+(c^0x30);
    return s?-r:r;
}

}using IO::fast_read;
#define MAXN 500001
int arr[MAXN];
vector<int> pos[MAXN];

int main()
{
    freopen("kur.in", "r", stdin);
    freopen("kur.out", "w", stdout);
    int n, m;
    n = fast_read();
    m = fast_read();
    for(int i = 1; i <= n; i++)pos[arr[i] = fast_read()].push_back(i);
    while(m--)
    {
        int l = fast_read();
        int r = fast_read();
        bool flag = false;int t = 20, x;
        while(!flag && t--)
        {
            x = arr[rand()%(r-l+1)+l];
            int p = upper_bound(pos[x].begin(), pos[x].end(), l-1)-pos[x].begin();
            int q = lower_bound(pos[x].begin(), pos[x].end(), r+1)-pos[x].begin();
            if(q-p > (r-l+1)/2)flag = true;
        }
        if(flag)printf("%d\n", x);
        else puts("0");
    }
    return 0;
}