QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 1024 MB Total points: 100
统计

给定长为 $n$ 的序列,$q$ 次询问区间 $[l,r]$ 的最短子区间 $[l',r']$,满足所有在 $[l,r]$ 中出现的数也在 $[l',r']$ 中出现. 你只需要输出 $[l',r']$ 的长度 $r'-l'+1$。

输入格式

第一行一个正整数 $n$。

接下来一行有 $n$ 个正整数,表示序列的元素。

接下来一行有一个正整数 $q$。

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

输出格式

$q$ 行,每行一个正整数表示答案。

样例数据

样例 1 输入

5
1 3 2 3 4
3
2 4
1 3
2 5

样例 1 输出

2
3
3

子任务

Idea:qwaszx,Solution:qwaszx,Code:qwaszx,Data:qwaszx

对于 $20\%$ 的数据,满足 $n,q,a_i\leq 5\times 10^3$。

对于 $50\%$ 的数据,满足 $n,q,a_i\leq 5\times 10^4$。

对于 $100\%$ 的数据,满足 $1\leq n,q\leq 2\times 10^6$,$1\leq a_i\leq n$。

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.