QOJ.ac

QOJ

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

#4339. rmscne

Statistics

给定长为 $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$。

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.