#P4509. [CTSC2015] 葱

[CTSC2015] 葱

Description

Xiao Cong and Xiao Xu are good friends. Since Xiao Cong pulled 1 UR and 2 SR in an 11-roll, Xiao Xu felt that Xiao Cong is very lucky, so he gave him a problem to test his luck.

Xiao Xu first drew NN points on the plane, denoted as P1,P2,...,PNP_1, P_2, ..., P_N.

He connected these NN points in order, that is, he connected (P1,P2),(P2,P3),...,(PN1,PN)(P_1, P_2), (P_2, P_3), ..., (P_{N-1}, P_N) to obtain N1N-1 line segments.

Then, each time Xiao Xu drew a line on the plane and asked how many segments this line intersects. In particular, intersection at a segment endpoint counts as intersecting, and if the line completely covers a segment, it also counts as intersecting. Such a question is obviously easy for Xiao Cong; he can give the correct answer by intuition alone thanks to his luck.

To further test Xiao Cong’s luck, Xiao Xu increased the difficulty: in addition to each query, he would occasionally insert a new point PP between PiP_i and Pi+1P_{i+1}, then relabel all points in order; that is, the indices of points after PiP_i increase by one, and point PP becomes the new point Pi+1P_{i+1}.

In particular, point PP can also be inserted before the first point or after the last point.

Xiao Cong is still able to answer easily, so Xiao Xu raised the difficulty again:

After each insertion or query, Xiao Xu recorded all the resulting segments and regarded them as a historical version. Historical version TT denotes the state after the TT-th operation.

The insertion operation was changed to: based on a certain historical version TT, insert a point PP to obtain a new historical version.

The query was changed to: for a historical version TT, given a line, ask how many segments this line will intersect.

Although Xiao Cong has great luck, he is helpless in the face of such a problem. He turns to you, a participant of CTSC, to help him solve it.

Input Format

The first line contains three integers N,M,CN, M, C, denoting the initial number of points, the total number of operations, and whether the data are encrypted.

If C=1C=1, it means the data are encrypted. In each query operation, X0,Y0,X,YX_0, Y_0, X, Y and in each insertion operation, X,YX, Y are encrypted; you need to XOR them with last_ans to obtain the correct data, where last_ans is the answer to the previous query. Initially, last_ans =0= 0.

The next NN lines each contain two integers; on the ii-th line, the two integers denote the coordinates of PiP_i.

The next MM lines describe Xiao Xu’s MM operations. The result after the ii-th operation (1-indexed) is historical version ii.

For each operation, there is first a letter indicating the operation type.

  • If the letter is 'H', this is a query operation. Then five integers T,X0,Y0,X,YT, X_0, Y_0, X, Y follow, meaning that under historical version TT, Xiao Xu gives a line passing through (X0,Y0)(X_0, Y_0) with direction (X,Y)(X, Y), and Xiao Cong must answer how many segments it intersects.
  • If the letter is 'Z', this is an insertion operation. Then four numbers T,i,X,YT, i, X, Y follow, meaning that based on historical version TT, Xiao Xu inserts a point with coordinates (X,Y)(X, Y) after PiP_i. In particular, if i=0i=0, it means the point is inserted before P1P_1.

Output Format

For each query operation, output one line with one integer representing the correct answer Xiao Cong should give.

2 3 0
0 0
1 1
H 0 1 0 -1 1
H 1 0 1 1 1
H 2 -1 -1 1 1
1
0
1

Hint

Sample explanation 1:

For the third query, the line completely covers a segment, and Xiao Xu considers this as intersecting as well.

Constraints and notes:

All operations satisfy that in each query operation, TT is less than or equal to the current number of operations, and all input numbers are integers.

There are the following 4 special testdata groups, which are pairwise disjoint:

  1. For 10% of the testdata, 1N,M10001 \le N, M \le 1000.
  2. For 15% of the testdata, for the ii-th operation, T=i1T = i - 1.
  3. For 15% of the testdata, C=0C=0 and there are no modification operations.
  4. For 15% of the testdata, for query operations, Y=0Y=0 (this refers to the decrypted data), i.e., the given line is parallel to the xx-axis.

The above testdata also guarantee 1N,M5×1041 \le N, M \le 5 \times 10^4.

For 100% of the testdata, 1N,M1051 \le N, M \le 10^5, all coordinates are within [108,108][-10^8, 10^8], and within each dataset the sum of answers over all queries does not exceed 10610^6. The number of insertion operations does not exceed 5×1045 \times 10^4. Note that these segments may intersect each other.

Translated by ChatGPT 5