#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 points on the plane, denoted as .
He connected these points in order, that is, he connected to obtain 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 between and , then relabel all points in order; that is, the indices of points after increase by one, and point becomes the new point .
In particular, point 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 denotes the state after the -th operation.
The insertion operation was changed to: based on a certain historical version , insert a point to obtain a new historical version.
The query was changed to: for a historical version , 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 , denoting the initial number of points, the total number of operations, and whether the data are encrypted.
If , it means the data are encrypted. In each query operation, and in each insertion operation, 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 .
The next lines each contain two integers; on the -th line, the two integers denote the coordinates of .
The next lines describe Xiao Xu’s operations. The result after the -th operation (1-indexed) is historical version .
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 follow, meaning that under historical version , Xiao Xu gives a line passing through with direction , and Xiao Cong must answer how many segments it intersects.
- If the letter is 'Z', this is an insertion operation. Then four numbers follow, meaning that based on historical version , Xiao Xu inserts a point with coordinates after . In particular, if , it means the point is inserted before .
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, 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:
- For 10% of the testdata, .
- For 15% of the testdata, for the -th operation, .
- For 15% of the testdata, and there are no modification operations.
- For 15% of the testdata, for query operations, (this refers to the decrypted data), i.e., the given line is parallel to the -axis.
The above testdata also guarantee .
For 100% of the testdata, , all coordinates are within , and within each dataset the sum of answers over all queries does not exceed . The number of insertion operations does not exceed . Note that these segments may intersect each other.
Translated by ChatGPT 5
京公网安备 11011102002149号