#P16699. [MCO 2026] 知道得越少越好

    ID: 19029 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>贪心前缀和差分2026MCC/MCO(马来西亚)

[MCO 2026] 知道得越少越好

Problem Description

The dragon Evirir wrote NN pages about Olympiad in Informatics. For each integer i=0,1,,N1i = 0, 1, \ldots, N - 1, there is exactly one page whose amount of knowledge is ii. Evirir will bind these pages into a book. Formally, Evirir will choose a sequence A0,A1,,AN1A_0, A_1, \ldots, A_{N - 1} of length NN consisting of pairwise distinct integers from 00 to N1N - 1. Then, it will make a book such that page ii (0iN10 \le i \le N - 1) has knowledge amount AiA_i.

Due to ancient dragon laws, the knowledge amounts of some pages are fixed. The law gives NN integers B0,B1,,BN1B_0, B_1, \ldots, B_{N - 1}. For each 0iN10 \le i \le N - 1, if Bi1B_i \ne -1, then it must hold that Ai=BiA_i = B_i. There are exactly KK values of BiB_i with Bi1B_i \ne -1.

Evirir wants its MM students (numbered 0,1,,M10, 1, \ldots, M - 1) to read the whole book. However, due to short attention spans, each student ii will only read pages Li,Li+1,,RiL_i, L_i + 1, \ldots, R_i. A student's knowledge gain is defined as the sum of the knowledge amounts of the pages that the student reads.

If Evirir binds these pages in an optimal way, what is the maximum possible total knowledge gain of all students?

Input Format

The first line contains three integers NN, MM, and KK, separated by spaces.

The second line contains NN integers B0,B1,,BN1B_0, B_1, \ldots, B_{N - 1}, separated by spaces.

The next MM lines follow. The ii-th of them contains two integers LiL_i and RiR_i, separated by spaces.

Output Format

Output one integer, the maximum possible total knowledge gain for all students.

5 2 5
3 4 1 0 2
0 2
1 4
15
5 3 2
2 -1 -1 1 -1
2 2
0 0
3 4
10
5 3 0
-1 -1 -1 -1 -1
1 3
4 4
0 4

20

Hint

Hint

Sample 1\underline{Sample\ 1}

This sample applies to subtasks 1, 4, and 6.

Evirir wrote N=5N = 5 pages, and there are M=2M = 2 students. All K=NK = N pages are fixed.

  • Student 0 reads pages 0 to 2 and gains 3+4+1=83 + 4 + 1 = 8 knowledge.
  • Student 1 reads pages 1 to 4 and gains 4+1+0+2=74 + 1 + 0 + 2 = 7 knowledge.

Therefore, the total knowledge gain is 8+7=158 + 7 = 15.

Sample 2\underline{Sample\ 2}

This sample applies to subtasks 4 and 6.

There are K=2K = 2 fixed pages: 0 and 3. One optimal binding is A=[2,0,4,1,3]A = [2, 0, 4, 1, 3].

  • Student 0 reads pages 2 to 2 and gains 44 knowledge.
  • Student 1 reads pages 0 to 0 and gains 22 knowledge.
  • Student 2 reads pages 3 to 4 and gains 1+3=41 + 3 = 4 knowledge.

The total knowledge gain is 4+2+4=104 + 2 + 4 = 10. Note that there may be other optimal bindings.

Some examples of AA that Evirir cannot choose:

  • A=[4,0,3,1,2]A = [4, 0, 3, 1, 2]: page 0 is fixed as B0=2B_0 = 2, but here A0=4A_0 = 4.
  • A=[2,4,4,1,4]A = [2, 4, 4, 1, 4]: the knowledge amounts are not pairwise distinct.
  • A=[2,3,5,1,4]A = [2, 3, 5, 1, 4]: the knowledge amounts must be between 0 and N1N - 1.

Sample 3\underline{Sample\ 3}

This sample applies to subtasks 3, 4, and 6.

Since K=0K = 0, no page has a fixed knowledge amount. One optimal binding is A=[0,4,2,1,3]A = [0, 4, 2, 1, 3].

  • Student 0 reads pages 1 to 3 and gains 4+2+1=74 + 2 + 1 = 7 knowledge.
  • Student 1 reads pages 4 to 4 and gains 33 knowledge.
  • Student 2 reads pages 0 to 4 and gains 0+4+2+1+3=100 + 4 + 2 + 1 + 3 = 10 knowledge.

The total knowledge gain is 7+3+10=207 + 3 + 10 = 20.

Scoring

For all testdata, the input satisfies the following constraints:

  • 1N51051 \le N \le 5 \cdot 10^5
  • 1M1051 \le M \le 10^5
  • 0KN0 \le K \le N
  • For all 0iN10 \le i \le N - 1, 1BiN1-1 \le B_i \le N - 1
  • There are exactly KK indices ii such that Bi1B_i \ne -1
  • All fixed values are pairwise distinct: if Bi1B_i \ne -1 and Bj1B_j \ne -1 and iji \ne j, then BiBjB_i \ne B_j
  • For all 0iM10 \le i \le M - 1, 0LiRiN10 \le L_i \le R_i \le N - 1
Subtask Points Additional Constraints
11 1515 N,M5000N, M \le 5000, K=NK = N
22 1010 N,M5000N, M \le 5000, K=0K = 0, for all 0iM10 \le i \le M - 1, (Li,Ri)=(L0,R0)(L_i, R_i) = (L_0, R_0)
33 2525 N,M5000N, M \le 5000, K=0K = 0
44 1515 N,M5000N, M \le 5000
55 1010 for all 0iM10 \le i \le M - 1, Li=0L_i = 0
66 2525 --

Translated by ChatGPT 5