#P8473. [Aya Round 1 H] 破碎的历史

    ID: 9570 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>线段树二分洛谷原创Special JudgeO2优化洛谷月赛

[Aya Round 1 H] 破碎的历史

Background

Gensokyo has met its destruction, and the carrier of fantasy has already faded into fantasy.

Fortunately, the residents of Gensokyo have survived by chance, and they are trying to restore Gensokyo’s history. However, there are countless big and small events in history, and people can only remember some major events.

Perhaps, based on those important events, the minor events can be deduced?

Problem Description

On the positive half-axis of the number line, there are nn distinct special integer points colored black or white, with positions from left to right being p1,p2,,pnp_1,p_2,\cdots,p_n. Maintain a multiset of segments SS, initially empty.

There are qq operations. There are several types of operations, in the following formats:

  • 1 l r: Add to SS all segments [x,y][x,y] such that lxyrl \le x \le y \le r and both endpoints are special integer points.
  • 2 x: Revoke the segments added by the xx-th operation.

Initially and after each operation, assume you may perform any number (possibly zero) of coloring actions. Each time, choose a segment [x,y][x,y] from SS such that the special integer points at xx and yy are both black, then color all white special integer points inside this segment to black. Determine whether there exists at least one valid coloring method that makes all special integer points on the positive half-axis black (i.e., no white special integer points remain). Note: all queries are “hypothetical”, meaning different queries are independent and will not cause any actual modification to the number line.

Input Format

  • The first line contains two integers n,qn,q.
  • The second line contains nn integers p1,p2,,pnp_1,p_2,\cdots,p_n, representing the positions of the nn special integer points from left to right.
  • The third line contains nn integers a1,a2,,ana_1,a_2,\cdots,a_n, representing the colors of the special integer points. Here ai=0a_i=0 means white, and ai=1a_i=1 means black.
  • The next qq lines each contain two or three integers, describing one operation.

Output Format

  • Output a total of (q+1)(q+1) lines.
  • Initially and after each operation, output one line with one string:
    • yes means there exists a valid coloring method.
    • no means there does not exist a valid coloring method.
  • You may output the strings in any letter case. For example, yes, Yes, and YES are all accepted as indicating that a valid coloring method exists.
6 3
1 2 3 5 8 13
1 0 0 1 0 1
1 5 10
1 1 15
2 2

No
No
Yes
No

Hint

Sample Explanation

The positions/colors of the six special points on the positive half-axis are shown in the figure.

It is easy to see that not all points are black. Therefore, before any operation, output NO\verb!NO!.

After the first operation, three segments are added to SS in total: [5,5],[8,8],[5,8][5,5],[8,8],[5,8] (segments with overlapping endpoints are omitted in the figure). It is easy to see that no action can be performed at this time, so it is impossible to make all points black. Output NO\verb!NO!.

After the second operation, another 2020 segments are added into SS. After removing segments with overlapping endpoints, SS is shown in the figure. (To distinguish them, the edges added in the previous operation are marked in dark blue.)

One can find a plan to turn all special points in the figure black. Specifically, first choose the segment [1,5][1,5] in SS (it is easy to see that the special points at 11 and 55 are both black, so coloring is allowed), then the points at 22 and 33 can be colored.

Now you can choose the segment [3,13][3,13] in SS (in the previous step, point 33 became black, so [3,13][3,13] satisfies the condition) and color point 88 black.

Now all points are black, so output YES\verb!YES!. Again, the queries are independent of each other, and this only asks whether a coloring plan exists; it will not actually color the special integer points.

The third operation revokes all segments added into SS by the second operation. Therefore, it returns to the state where only the first operation exists. There is no plan that can color all points black, so output NO\verb!NO!.

Constraints

For all testdata, 1n,q5×1051 \le n,q \le 5 \times 10^5, ai{0,1}a_i \in \{0,1\}, 1l<r1091 \le l< r \le 10^9, 1pi1091 \le p_i \le 10^9. It is guaranteed that pip_i is strictly increasing, operation type 22 only revokes operation type 11, and each operation is revoked at most once.

Translated by ChatGPT 5