QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 512 MB Points totaux : 100

#18792. Sequence and Queries 34

Statistiques

Given two sequences of positive integers $a$ and $b$ of lengths $n$ and $m$ respectively, write a program to perform the following queries. All indices start from 1.

  • 1 y z: Perform $a[y] = z$ and then output $F(a, b)$. ($1 \le y \le n$, $1 \le z \le 10^5$)
  • 2 y z: Output $F(a[y..z], b)$. ($1 \le y \le z \le n$)
  • 3 y z: Output $f(b[y..m], b[z..m])$. ($1 \le y, z \le m$)
  • 4 p q r s: If the sequence $[b_p, b_{p+1}, \ldots, b_q, b_r, b_{r+1}, \ldots, b_s]$ is a contiguous subsequence of $b$, then output "yes", otherwise output "no". ($1 \le p \le q \le m$, $1 \le r \le s \le m$)

$a[l..r]$ is the subsequence $[a_l, a_{l+1}, \ldots, a_r]$. A similar definition holds for $b$.

For two sequences $x, y$:

  • $f(x, y)$ denotes the length of the longest common prefix of $x$ and $y$.
  • $F(x, y)$ is a pair of integers $(p, q)$, where $p$ is the maximum value of $f(z, y)$ over all suffixes $z$ of $x$, and $q$ is the number of $z$ that achieve this maximum.

Input

The first line contains an integer $n$, the length of $a$. ($1 \le n \le 10^5$)

The next line contains $n$ integers $a_1, a_2, \ldots, a_n$. ($1 \le a_i \le 10^5$)

The next line contains an integer $m$, the length of $b$. ($1 \le m \le 10^5$)

The next line contains $m$ integers $b_1, b_2, \ldots, b_m$. ($1 \le b_i \le 10^5$)

The next line contains an integer $q$, the number of queries. ($1 \le q \le 10^5$)

The next $q$ lines each contain a query as described above.

Output

For each query, output the result in order, each on its own line.

Examples

Input 1

10
1 2 3 3 3 1 2 3 2 1
3
1 3 1
10
3 1 3
4 3 3 2 2
2 2 10
1 3 2
2 7 9
2 7 10
2 3 9
2 2 8
1 7 1
1 4 2

Output 1

1
yes
1 2
1 3
0 3
1 1
1 1
1 1
2 1
2 1

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.