QOJ.ac

QOJ

Time Limit: 10.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#9302. 凯撒密码

Statistics

你听说过凯撒密码吗?它是最简单且最广为人知的加密技术之一。它以尤利乌斯·凯撒(Julius Caesar)的名字命名,凯撒曾用这种密码与他的将军们进行通信。

凯撒密码是一种替换加密,明文中的每个字母都被字母表上向后移动一定位置的字母所替换。字母表被视为循环的。例如,在拉丁字母表中,位移量为 1 时,A 会被 B 替换,B 会变成 C,Z 会变成 A,依此类推。

Kazusa 现在有一个长度为 $n$ 的整数数组 $a_1, a_2, \dots, a_n$,其中每个 $a_i$ 都在区间 $[0, 65\,536)$ 内。她想要多次使用凯撒密码对其进行加密。每次她选择一个区间 $[l, r]$ ($1 \le l \le r \le n$),并对该区间内的数字进行一次位移量为 1 的凯撒加密。形式化地,对于所有 $l \le i \le r$,这会将 $a_i$ 变为 $(a_i + 1) \pmod{65\,536}$。

然而,在 Kazusa 加密数组的同时,她的妹妹 Setsuna 对数组提出了一些疑问。每个询问都是针对当前数组状态的,此时数组可能已经经过了零次或多次凯撒加密。每个询问由三个整数 $x, y, L$ 给出,询问两个字符串 $a_x, a_{x+1} \dots a_{x+L-1}$ 和 $a_y, a_{y+1} \dots a_{y+L-1}$ 是否相同。

当 Kazusa 忙于加密时,她没有时间回答这些询问。你能帮帮她吗?

输入格式

第一行包含两个整数 $n, q$ ($1 \le n, q \le 500\,000$),分别表示数组的大小和操作的数量。 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i < 65\,536$),表示初始数组。 接下来的 $q$ 行描述了操作,每个操作属于以下两种类型之一:

  • 类型 1 操作包含三个整数 $1, l, r$ ($1 \le l \le r \le n$),表示 Kazusa 对区间 $[l, r]$ 内的数字进行了一次位移量为 1 的凯撒加密;
  • 类型 2 操作包含四个整数 $2, x, y, L$ ($1 \le x, y \le n, \max\{x, y\} + L - 1 \le n$),表示 Setsuna 询问两个字符串是否相同。

输出格式

对于每个类型 2 的操作,如果两个字符串相同,请在一行中输出 yes;否则输出 no

样例

样例输入 1

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

样例输出 1

no
yes
no
yes

样例输入 2

3 3
0 65535 65535
2 1 2 2
1 2 3
2 1 2 2

样例输出 2

no
yes

说明

第一个测试用例解释如下:

操作 数组 说明
1 $[1,2,1,2,1]$ $[1,2]$ 和 $[2,1]$ 不同
2 $[1,2,1,2,1]$ $[1,2,1]$ 和 $[1,2,1]$ 相同
3 $[2,2,1,2,1]$ 第一个元素位移了 1
4 $[2,2,2,3,2]$ 第三到第五个元素位移了 1
5 $[2,2,2,3,2]$ $[2,2,2,3]$ 和 $[2,2,3,2]$ 不同
6 $[2,2,2,3,2]$ $[2,2]$ 和 $[2,2]$ 相同

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#227EditorialOpen题解jiangly2025-12-13 00:21:00View

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.