[Ynoi Easy Round 2023] TEST_107

Luogu
IDLGP9991
Time4000ms
Memory512MB
DifficultyP6
线段树树状数组2023O2优化排序扫描线Ynoi
给一个长为 $n$ 的序列 $a$,下标为 $1$ 到 $n$,有 $m$ 次查询操作,每次给出一个区间 $[l,r]$,求一个子区间 $[l',r']$,满足 $l\le l'\le r'\le r$,$[l',r']$ 中出现过的值个数比 $[l,r]$ 中出现过的值个数少,且其长度即 $r'-l'+1$ 最大。若不存在这样的子区间,则输出 $0$。 ## Input 第一行两个数表示 $n,m$。 之后一行 $n$ 个数依次表示序列 $a$ 中的元素。 之后 $m$ 行,每行两个数 $l,r$ 表示一次查询,只需输出该子区间的长度,即 $r'-l'+1$。 ## Output 对于每次查询,输出一行一个数表示答案。 [samples] ## Note Idea:ccz181078,Solution:ccz181078,Code:ccz181078,Data:ccz181078 对于 $20\%$ 的数据,满足 $n,m\le100$。 对于 $40\%$ 的数据,满足 $n,m\le1000$。 对于另外 $20\%$ 的数据,满足 $a_i\le 10$。 对于 $100\%$ 的数据,满足 $1\le n,m,a_i\le 2\times 10^6$。
Samples
Input #1
5 4
1 3 2 3 4
2 4
1 3
2 5
1 1
Output #1
1
2
3
0
API Response (JSON)
{
  "problem": {
    "name": "[Ynoi Easy Round 2023] TEST_107",
    "description": {
      "content": "给一个长为 $n$ 的序列 $a$,下标为 $1$ 到 $n$,有 $m$ 次查询操作,每次给出一个区间 $[l,r]$,求一个子区间 $[l',r']$,满足 $l\\le l'\\le r'\\le r$,$[l',r']$ 中出现过的值个数比 $[l,r]$ 中出现过的值个数少,且其长度即 $r'-l'+1$ 最大。若不存在这样的子区间,则输出 $0$。",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 524288
    },
    "difficulty": {
      "LuoguStyle": "P6"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP9991"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "给一个长为 $n$ 的序列 $a$,下标为 $1$ 到 $n$,有 $m$ 次查询操作,每次给出一个区间 $[l,r]$,求一个子区间 $[l',r']$,满足 $l\\le l'\\le r'\\le r$,$[l',r']$ 中出现过的值个数比 $[l,r]$ 中出现过的值个数少,且其长度即 $r'-l'+1$ 最大。若不存在这样的子区间,则输出 $0$。\n\n## Input\n\n第一行两个数表示 $...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments