Topic links: https://ac.nowcoder.com/acm/contest/887/E
Links: https://ac.nowcoder.com/acm/contest/887/E
Source: Cattle-off network
Find the median
Time limit: C / C ++ 3 seconds to 6 seconds languages other
space restrictions: C / C ++ 131072K, other languages 262144K
64bit IO the Format:% LLD
space restrictions: C / C ++ 131072K, other languages 262144K
64bit IO the Format:% LLD
Title Description
Let median of some array be the number which would stand in the middle of this array if it was sorted beforehand. If the array has even length let median be smallest of of two middle elements. For example, median of the array [10,3,2,3,2] is 3 (i.e.
[2,2,3‾,3,10][2,2,\underline{3},3,10][2,2,3,3,10]). Median of the array [1,5,8,1] is 1 (i.e. [1,1‾,5,8][1,\underline{1},5,8][1,1,5,8]).
At first, you're given an empty sequence. There are N operations. The i-th operation contains two integers LiL_iLi and RiR_iRi. This means that adding Ri−Li+1R_i-L_i+1Ri−Li+1 integers Li,Li+1,...,RiL_i, L_i+1, ... , R_iLi,Li+1,...,Ri into the sequence. After each operation, you need to find the median of the sequence.
At first, you're given an empty sequence. There are N operations. The i-th operation contains two integers LiL_iLi and RiR_iRi. This means that adding Ri−Li+1R_i-L_i+1Ri−Li+1 integers Li,Li+1,...,RiL_i, L_i+1, ... , R_iLi,Li+1,...,Ri into the sequence. After each operation, you need to find the median of the sequence.
Enter a description:
The first line of the input contains an integer N (1≤N≤400000)N\ (1 \leq N \leq 400000)N (1≤N≤400000) as described above.
The next two lines each contains six integers in the following format, respectively:
- X1 X2 A1 B1 C1 M1X_1\ X_2\ A_1\ B_1\ C_1\ M_1X1 X2 A1 B1 C1 M1
- Y1 Y2 A2 B2 C2 M2Y_1\ Y_2\ A_2\ B_2\ C_2\ M_2Y1 Y2 A2 B2 C2 M2
These values are used to generate Li,RiL_i, R_iLi,Ri as follows:
We define:
- Xi=(A1×Xi−1+B1×Xi−2+C1) module M1X_i = (A_1 \times X_{i-1} + B_1 \times X_{i-2} + C_1)\ module\ M_1Xi=(