#P3759. [TJOI2017] 不勤劳的图书管理员
[TJOI2017] 不勤劳的图书管理员
Description
At Jialidun University, there is an Imperial Library. Xiao Dou is a librarian in the library’s reading room. His job is to keep the books in order, so disorder annoys him. A pair of books that are out of order causes an annoyance equal to the sum of their page counts. There are books currently in a jumbled order. During the next days, readers’ use will cause the books’ positions to change each day. Xiao Dou is required to tidy the books at least once during these days. He wants to know, if he does not tidy during the first days, what his annoyance will be on day , so that he can choose the day with the minimum annoyance to tidy.
Input Format
The first line contains two integers , denoting books and days. The next lines each contain two integers , meaning that book should be placed at position , and this book has pages. It is guaranteed that no two books have the same intended position. The next lines each contain two integers and , meaning that on day , book and book swap positions due to readers’ usage.
Output Format
Output lines. The -th line is the annoyance on day if he does not tidy during the first days. Since this number can be large, output the result modulo .
5 5
1 1
2 2
3 3
4 4
5 5
1 5
1 5
2 4
5 3
1 3
42
0
18
28
48
Hint
Constraints
- For of the testdata, , , .
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号