Universal Cup Judging System

Universal Cup

Time Limit: 3.5 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

A rururutata type sequence is defined as a sequence that can be written as $r + r + r + t + t$ ($+$ means concatenation) using non-empty sequences $r$ and $t$.

You are given an integer sequence $S = (S_1, S_2, \dots, S_N)$ of length $N$. There are $Q$ queries, which you must process in order.

In each query, integers $L$ and $R$ are given. Determine whether there exists a rururutata type sequence as a contiguous subarray of $(S_L, S_{L+1}, \dots, S_R)$.

Input

The input is given in the following format:

N
S1 S2 ... SN
Q
query1
query2
:
queryQ

Each query is given in the following format:

L R

Constraints

  • $1 \le N \le 5 \times 10^5$
  • $1 \le S_i \le N$ ($1 \le i \le N$)
  • $1 \le Q \le 5 \times 10^5$
  • $1 \le L \le R \le N$
  • All input values are integers.

Output

Print $Q$ lines.

On the $i$-th line, print Yes if a rururutata type sequence exists for the $i$-th query, and No otherwise.

Example

Input 1

17
3 3 3 2 2 2 4 3 4 3 4 3 2 2 2 2 2
5
1 5
4 12
2 6
8 15
13 17

Output 1

Yes
Yes
No
No
Yes

Note

For the first query, $(S_1, S_2, S_3, S_4, S_5) = (3, 3, 3, 2, 2)$ is a rururutata type sequence. The condition is satisfied by taking $r = (3)$ and $t = (2)$.

For the second query, among $(S_4, S_5, \dots, S_{12})$, the contiguous subarray $(S_4, S_5, \dots, S_{10}) = (2, 2, 2, 4, 3, 4, 3)$ is a rururutata type sequence. The condition is satisfied by taking $r = (2)$ and $t = (4, 3)$.

For the third query, $(3, 3, 2, 2, 2)$ is not a rururutata type sequence, and it clearly does not contain any shorter rururutata type sequence either.

For the fourth query, note that $(3, 3, 3, 2, 2)$ is not a contiguous subarray.

For the fifth query, note that it is allowed for $r$ and $t$ to be the same.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1487EditorialOpen题解jianglyView
#1345EditorialOpen题解MilmonView

Discussions

About Discussions

The discussion section is only for posting: 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.
  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.