QOJ.ac

QOJ

时间限制: 3.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#11258. 另一个回文问题

统计

给定一个长度为 $n$ 的序列 $A$,记序列 $A$ 中的第 $i$ 个元素为 $a_i$。接下来有 $q$ 次操作,分为修改操作和查询操作。每次修改操作给定一个区间 $[l, r]$ 和一个正整数 $v$,表示将 $a_l, a_{l+1}, \dots, a_r$ 加上 $v$。每次查询操作给定一个区间 $[l, r]$,询问序列 $a_l, a_{l+1}, \dots, a_r$ 是否可以通过若干次“交换”操作变为回文序列。题目保证查询的区间长度为偶数。对于每次“交换”,可以选择一个满足 $l \le i \le r - 2$ 的下标 $i$,交换 $a_i$ 和 $a_{i+2}$。注意,查询操作仅判断序列是否可以通过“交换”形成回文序列,并不会改变序列 $A$ 本身。

输入格式

第一行包含两个整数 $n, q$ ($1 \le n, q \le 2 \times 10^5$),分别表示序列 $A$ 的长度和操作次数。

第二行包含 $n$ 个整数,第 $i$ 个数表示序列 $A$ 中的第 $i$ 个元素 $a_i$ ($1 \le a_i \le 10^9$)。

接下来的 $q$ 行,每行表示一个操作。如果是修改操作,包含 4 个整数 $op, l, r, v$,其中 $op = 0$,$l, r, v$ 的含义与题目描述一致;否则,包含 3 个整数 $op, l, r$,其中 $op = 1$,表示查询操作,$l, r$ 的含义与题目描述一致($op \in \{0, 1\}, 1 \le l \le r \le n, 1 \le v \le 10^9$,且当 $op = 1$ 时保证 $r - l + 1$ 为偶数)。

输出格式

对于每次查询,如果序列可以通过“交换”形成回文序列,输出 “YES”,否则输出 “NO”。你可以以任何形式输出答案(大小写不敏感),例如 “yEs”、“yes”、“Yes” 和 “YES” 均被视为肯定回答。

样例

样例输入 1

5 5
2 1 2 1 2
0 2 4 1
1 1 2
1 2 3
1 3 4
1 4 5

样例输出 1

YES
NO
NO
YES

样例输入 2

9 9
1 2 3 3 2 1 1 2 3
1 1 6
1 4 9
1 2 5
0 1 5 12
1 1 6
1 4 9
0 8 9 12
1 4 9
1 3 8

样例输出 2

YES
YES
YES
NO
NO
YES
YES

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.