#P5883. [CTSC2013] 没头脑和不高兴

[CTSC2013] 没头脑和不高兴

Problem Description

Not Thinking and Unhappy are a pair of inseparable good friends. They go to school together and play together.

One day, they got together to play a card game. There are a total of NN cards, and each card has a number from 1N1-N on it. The numbers on any two cards are different. According to the rules they made, at the start of each round, all cards must be arranged in order from 1N1-N. After happily finishing a round, they found that the order of the cards had become a complete mess, and sorting them back is quite troublesome.

They laid the messy cards in a row on the table and began sorting. Unhappy, having lost in the last round, was very unhappy. He only sorted the cards in the odd positions into increasing order, and then pushed the remaining work to Not Thinking. Not Thinking was really not thinking: he used a somewhat clumsy sorting method. Each time, he finds two adjacent cards that are in the wrong order and swaps them, until the whole sequence is sorted.

You, who enjoy exploring, want to study how much time Not Thinking spends swapping cards when the initial permutation is random. Assume each swap costs time 11. You want to find the expected value of his sorting time. In addition, to analyze this better, you also want to compute the variance of the time spent. Furthermore, if the positions sorted by Unhappy change, can you still find the expected sorting time of Not Thinking?

Input Format

  • The input file has M+1M+1 lines.
  • The first line contains two positive integers NN, MM.
  • The next MM lines each contain three integers ll, rr, vv. Here 1lrn1 \le l \le r \le n, v{0,1}v\in\{0,1\}. If v=0v=0, it means Unhappy will no longer sort positions from ll to rr; otherwise, if v=1v=1, it means the positions sorted by Unhappy will include ll to rr.

Output Format

  • The output file has M+2M+2 lines. Each line outputs a rational number in the form p/q, where gcd(p,q)=1\gcd(p,q)=1, q1q \ge 1, p,qZp,q \in Z.
  • The first line outputs the expected sorting time of Not Thinking under the initial condition.
  • The second line outputs the variance of Not Thinking's sorting time under the initial condition.
  • The next MM lines output, respectively, the expected sorting time of Not Thinking after the first several modifications to the positions sorted by Unhappy.
3 3
2 3 0
2 2 1
1 3 1

2/3
2/9
3/2
1/1
0/1

Hint

Sample Explanation

Under the initial condition, Unhappy will sort the cards at positions 11 and 33. For permutations (1,2,3)(1,2,3) and (3,2,1)(3,2,1), he will make them into (1,2,3)(1,2,3), so Not Thinking does not need to do anything. For permutations (1,3,2)(1,3,2) and (2,3,1)(2,3,1), he will make them into (1,3,2)(1,3,2), and Not Thinking needs one swap. For permutations (2,1,3)(2,1,3) and (3,1,2)(3,1,2), he will make them into (2,1,3)(2,1,3), and Not Thinking needs one swap. Therefore, the expected time Not Thinking spends is $\frac{0 \times 2+1 \times 2+1\times 2}{6}=\frac{2}{3}$; the variance is $\frac{ (0-\frac{2}{3})^2 \times 2 + (1-\frac{2}{3})^2 \times 2+(1-\frac{2}{3})^2 \times 2 }{6}=\frac{2}{9}$.

After the first modification, Unhappy will only sort position 11, which is the same as not sorting at all. After the second modification, he will sort positions 11, 22. After the last modification, he will sort positions 11, 22, 33, so Not Thinking does not need to participate in sorting at all. Based on this, you can compute the expected sorting time of Not Thinking in the corresponding cases.

Scoring

  • If the first two lines are correct but the remaining lines are wrong, you can get 40%40\% of the score.
  • If the first two lines are wrong but the remaining lines are correct, you can get 50%50\% of the score.
  • If all output lines are completely correct, you can get 100%100\% of the score.
  • In all other cases, you get no score.

Constraints

Test Point ID Value of NN Value of MM
11 44 1010
22 1111 100100
33 100100 10310^3
44 10011001 10410^4
55 7859078590 10510^5
66 8793387933
77 9500095000
88 9944599445
99 9999999999
1010 100000100000

Translated by ChatGPT 5