QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#6269. 模棱两可

Statistics

给定一个序列 $a_1,a_2,\dots,a_n$,每次询问一个区间 $[l,r]$ 内出现最多的数的出现次数。

但今天我们不太关心问题的精确答案,只关心问题的数量级。因此,如果精确答案是 $ans$,你的回答只要在 $[0.5ans, 2ans]$ 内就算你对。

输入格式

第一行两个正整数 $n,q$ 表示序列长度和询问次数。

接下来一行输入 $n$ 个正整数,分别表示 $a_1,a_2,\dots,a_n$。

接下来 $q$ 行每行两个正整数 $l,r$ 表示一个询问区间。

输出格式

输出 $q$ 行,每行一个数表示答案。

样例数据

样例输入

10 3
1 1 4 5 1 4 1 9 1 9
1 10
1 5
3 10

样例输出

5
3
3

样例 解释

注意样例输出是严格正确的答案,但分别在 $[3,10], [2,6], [2, 6]$ 区间内的输出都是正确的。

子任务

对于 $100\%$ 的数据,保证 $1\le n,q\le 10^6$,$1\leq a_i\leq n$。

对于测试点 $1\sim 3$,保证 $n, q\leq 10^3$。

对于测试点 $4\sim 5$,保证 $n\leq 10^3$。

对于测试点 $6\sim 7$,保证 $n,q\leq 10^5$。

对于测试点 $8\sim 10$,无特殊限制。

提示

本题输入输出范围较大,可能需要使用 IO 优化,提供如下模板,并注意注释处是文件 IO 的开启位置:

using u32 = unsigned;
struct IO_Tp
{
    const static int _I_Buffer_Size = 30 << 20;
    char _I_Buffer[_I_Buffer_Size], *_I_pos = _I_Buffer;

    const static int _O_Buffer_Size = 8 << 20;
    char _O_Buffer[_O_Buffer_Size], *_O_pos = _O_Buffer;

    u32 m[10000];

    IO_Tp()
    {
//        freopen("ambiguous.in", "r", stdin);
//        freopen("ambiguous.out", "w", stdout);
        constexpr u32 e0 = '\0\0\0\1', e1 = '\0\0\1\0', e2 = '\0\1\0\0', e3 = '\1\0\0\0';
        int x = 0;
        for (u32 i = 0, c0 = '0000'; i != 10; ++i, c0 += e0)
            for (u32 j = 0, c1 = c0; j != 10; ++j, c1 += e1)
                for (u32 k = 0, c2 = c1; k != 10; ++k, c2 += e2)
                    for (u32 l = 0, c3 = c2; l != 10; ++l, c3 += e3)
                        m[x++] = c3;

        fread(_I_Buffer, 1, _I_Buffer_Size, stdin);
    }
    ~IO_Tp() { fwrite(_O_Buffer, 1, _O_pos - _O_Buffer, stdout); }

    IO_Tp &operator>>(int &res)
    {
        while (!isdigit(*_I_pos))
            ++_I_pos;
        res = *_I_pos++ - '0';
        while (isdigit(*_I_pos))
            res = res * 10 + (*_I_pos++ - '0');
        return *this;
    }

    IO_Tp &operator<<(int x)
    {
        if (x == 0)
        {
            *_O_pos++ = '0';
            return *this; 
        }
        static char _buf[35];
        char *_pos = _buf + 35;
        while (x >= 10000)
            *--reinterpret_cast<u32 *&>(_pos) = m[x % 10000], x /= 10000;
        *--reinterpret_cast<u32 *&>(_pos) = m[x];
        _pos += (x < 1000) + (x < 100) + (x < 10);
        _O_pos = std::copy(_pos, _buf + 35, _O_pos);
        return *this;
    }

    IO_Tp &operator<<(char ch)
    {
        *_O_pos++ = ch;
        return *this;
    }
} IO;
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.