CF1142B.Lynyrd Skynyrd

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Recently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation pp of length nn, and Skynyrd bought an array aa of length mm, consisting of integers from 11 to nn.

Lynyrd and Skynyrd became bored, so they asked you qq queries, each of which has the following form: "does the subsegment of aa from the ll-th to the rr-th positions, inclusive, have a subsequence that is a cyclic shift of pp?" Please answer the queries.

A permutation of length nn is a sequence of nn integers such that each integer from 11 to nn appears exactly once in it.

A cyclic shift of a permutation (p1,p2,…,pn)(p_1, p_2, \ldots, p_n) is a permutation (pi,pi+1,…,pn,p1,p2,…,pi−1)(p_i, p_{i + 1}, \ldots, p_{n}, p_1, p_2, \ldots, p_{i - 1}) for some ii from 11 to nn. For example, a permutation (2,1,3)(2, 1, 3) has three distinct cyclic shifts: (2,1,3)(2, 1, 3), (1,3,2)(1, 3, 2), (3,2,1)(3, 2, 1).

A subsequence of a subsegment of array aa from the ll-th to the rr-th positions, inclusive, is a sequence ai1,ai2,…,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} for some i1,i2,…,iki_1, i_2, \ldots, i_k such that l≤i1<i2<…<ik≤rl \leq i_1 \lt i_2 \lt \ldots \lt i_k \leq r.

最近,Lynyrd 和 Skynyrd 去了一家商店,Lynyrd 购买了一个长度为 nn 的排列 pp,而 Skynyrd 购买了一个长度为 mm 的数组 aa,其中每个元素均为 11 到 nn 之间的整数。

Lynyrd 和 Skynyrd 感到无聊,于是向你提出了 qq 个询问,每个询问的形式为:“数组 aa 中从第 ll 个位置到第 rr 个位置(含端点)的子段中,是否存在一个子序列是 pp 的某个循环移位?” 请回答这些询问。

长度为 nn 的排列是指一个由 nn 个整数组成的序列,其中 11 到 nn 中的每个整数恰好出现一次。

排列 (p1,p2,…,pn)(p_1, p_2, \ldots, p_n) 的一个循环移位是指形如 (pi,pi+1,…,pn,p1,p2,…,pi−1)(p_i, p_{i + 1}, \ldots, p_{n}, p_1, p_2, \ldots, p_{i - 1}) 的排列,其中 ii 为 11 到 nn 之间的某个整数。例如,排列 (2,1,3)(2, 1, 3) 有三个不同的循环移位:(2,1,3)(2, 1, 3)、(1,3,2)(1, 3, 2) 和 (3,2,1)(3, 2, 1)。

数组 aa 中从第 ll 个位置到第 rr 个位置(含端点)的子段的一个子序列,是指形如 ai1,ai2,…,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} 的序列,其中下标满足 l≤i1<i2<…<ik≤rl \leq i_1 \lt i_2 \lt \ldots \lt i_k \leq r。

输入格式

The first line contains three integers nn, mm, qq (1≤n,m,q≤2⋅1051 \le n, m, q \le 2 \cdot 10^5) — the length of the permutation pp, the length of the array aa and the number of queries.

The next line contains nn integers from 11 to nn, where the ii-th of them is the ii-th element of the permutation. Each integer from 11 to nn appears exactly once.

The next line contains mm integers from 11 to nn, the ii-th of them is the ii-th element of the array aa.

The next qq lines describe queries. The ii-th of these lines contains two integers lil_i and rir_i (1≤li≤ri≤m1 \le l_i \le r_i \le m), meaning that the ii-th query is about the subsegment of the array from the lil_i-th to the rir_i-th positions, inclusive.

第一行包含三个整数 nn、mm、qq(1≤n,m,q≤2⋅1051 \le n, m, q \le 2 \cdot 10^5)——分别表示排列 pp 的长度、数组 aa 的长度以及查询次数。

下一行包含 nn 个从 11 到 nn 的整数,其中第 ii 个数为排列 pp 的第 ii 个元素。11 到 nn 中的每个整数恰好出现一次。

再下一行包含 mm 个从 11 到 nn 的整数,其中第 ii 个数为数组 aa 的第 ii 个元素。

接下来 qq 行描述查询。其中第 ii 行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤m1 \le l_i \le r_i \le m),表示第 ii 个查询针对数组 aa 中从第 lil_i 个位置到第 rir_i 个位置(含端点)的子段。

输出格式

Print a single string of length qq, consisting of 00 and 11, the digit on the ii-th positions should be 11, if the subsegment of array aa from the lil_i-th to the rir_i-th positions, inclusive, contains a subsequence that is a cyclic shift of pp, and 00 otherwise.

输出一个长度为 qq 的字符串,仅由字符 00 和 11 组成;其中第 ii 位上的数字应为 11,当且仅当数组 aa 中从第 lil_i 位到第 rir_i 位(含端点)的子段包含一个子序列,该子序列是 pp 的某个循环移位;否则为 00。

输入输出样例

  • 输入#1

    3 6 3
    2 1 3
    1 2 3 1 2 3
    1 5
    2 6
    3 5

    输出#1

    110
  • 输入#2

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

    输出#2

    010

说明/提示

In the first example the segment from the 11-st to the 55-th positions is 1,2,3,1,21, 2, 3, 1, 2. There is a subsequence 1,3,21, 3, 2 that is a cyclic shift of the permutation. The subsegment from the 22-nd to the 66-th positions also contains a subsequence 2,1,32, 1, 3 that is equal to the permutation. The subsegment from the 33-rd to the 55-th positions is 3,1,23, 1, 2, there is only one subsequence of length 33 (3,1,23, 1, 2), but it is not a cyclic shift of the permutation.

In the second example the possible cyclic shifts are 1,21, 2 and 2,12, 1. The subsegment from the 11-st to the 22-nd positions is 1,11, 1, its subsequences are not cyclic shifts of the permutation. The subsegment from the 22-nd to the 33-rd positions is 1,21, 2, it coincides with the permutation. The subsegment from the 33 to the 44 positions is 2,22, 2, its subsequences are not cyclic shifts of the permutation.

在第一个例子中,第 11 个到第 55 个位置的子段为 1,2,3,1,21, 2, 3, 1, 2。其中存在一个子序列 1,3,21, 3, 2,它是该排列的一个循环移位。第 22 个到第 66 个位置的子段也包含一个子序列 2,1,32, 1, 3,它恰好等于该排列。第 33 个到第 55 个位置的子段为 3,1,23, 1, 2,其中长度为 33 的子序列仅有一个(即 3,1,23, 1, 2),但它不是该排列的循环移位。

在第二个例子中,可能的循环移位有 1,21, 2 和 2,12, 1。第 11 个到第 22 个位置的子段为 1,11, 1,其所有子序列均不是该排列的循环移位。第 22 个到第 33 个位置的子段为 1,21, 2,它与该排列完全相同。第 33 个到第 44 个位置的子段为 2,22, 2,其所有子序列均不是该排列的循环移位。

输入解题思路,AI测评打分。不知道怎么写?

首页