#P12194. [NOISG 2025 Prelim] Snacks

    ID: 13695 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 4 上传者: 标签>线段树平衡树2025颜色段均摊(珂朵莉树 ODT)NOISG(新加坡)STL

[NOISG 2025 Prelim] Snacks

题目描述

Shor the Duck has prepared nn plates of snacks to enjoy while watching movies! The ii-th plate initially contains a snack with a deliciousness value of a[i]a[i].

You need to process qq queries. In the jj-th query, Shor will do both of the following, in order:

  1. Eat every snack whose deliciousness is between l[j]l[j] and r[j]r[j] (inclusive).
  2. Then, replace each eaten snack with a new snack of deliciousness x[j]x[j].

Before processing any queries, and after each query, Shor wants you to determine the sum of deliciousness of snacks across all plates.

Formally, you are given an array aa of length nn and must process qq queries. Before processing any queries, print the sum of all elements in aa. In the jj-th query, update every element a[i]a[i] such that l[j]a[i]r[j]l[j] \leq a[i] \leq r[j] by setting a[i]=x[j]a[i] = x[j], then print the updated sum of all elements in aa.

输入格式

Your program must read from standard input.

The first line of input contains two space-separated integers nn and qq.

The second line of input contains nn space-separated integers a[1],a[2],,a[n]a[1], a[2], \ldots, a[n].

The following qq lines of input each contain three space-separated integers. The jj-th of these lines contains l[j],r[j]l[j], r[j], and x[j]x[j], describing the jj-th query.

输出格式

Your program must print to standard output.

The output should contain q+1q + 1 lines.

The first line of output should contain a single integer, the sum of all elements in a before all queries.

The following qq lines of input should each contain one integer. The ii-th of these lines should contain the sum of elements in a after the ii-th query.

5 3
1 6 2 4 6
6 6 3
2 2 3
3 3 5
19
13
14
20
6 4
929 121 5 3 919 72
1 133 0
70 79 0
900 999 0
1 1000 0
2049
1848
1848
0
0
6 5
7 72 727 123 321 9
7 9 10
10 72 727
111 222 30
123 727 99
111 222 333
1259
1263
3352
3259
525
525

提示

Subtasks

For all test cases, the input will satisfy the following bounds:

  • 1n2000001 \leq n \leq 200\,000
  • 0q2000000 \leq q \leq 200\,000
  • 0a[i]1090 \leq a[i] \leq 10^9 for all 1in1 \leq i \leq n
  • 0x[j]1090 \leq x[j] \leq 10^9 for all 1jq1 \leq j \leq q
  • 0l[j]r[j]1090 \leq l[j] \leq r[j] \leq 10^9 for all 1jq1 \leq j \leq q

Your program will be tested on input instances that satisfy the following restrictions:

Subtask Marks Additional Constraints
00 Sample test cases
11 55 q=0q = 0
22 1212 n,q2000n, q \leq 2000
33 2121 l[j]=r[j]200000l[j] = r[j] \leq 200\,000 and a[i],x[j]200000a[i], x[j] \leq 200\,000
44 1313 l[j]=r[j]l[j] = r[j]
55 1616 x[j]=0x[j] = 0
66 3333 No additional constraints

Sample Test Case 1 Explanation

This test case is valid for subtasks 2,3,42, 3, 4, and 66.

Sample Test Case 2 Explanation

This test case is valid for subtasks 2,52, 5, and 66.

Sample Test Case 3 Explanation

This test case is valid for subtasks 22 and 66.

Before all queries, the array a is [7,72,727,123,321,9][7, 72, 727, 123, 321, 9], with a sum of 12591259.

After the first query, the array a becomes [10,72,727,123,321,10][10, 72, 727, 123, 321, 10], with a sum of 12631263.

After the second query, the array a becomes [727,727,727,123,321,727][727, 727, 727, 123, 321, 727], with a sum of 33523352.

After the third query, the array a becomes [727,727,727,30,321,727][727, 727, 727, 30, 321, 727], with a sum of 32593259.

After the fourth query, the array a becomes [99,99,99,30,99,99][99, 99, 99, 30, 99, 99], with a sum of 525525.

After the fifth query, the array a becomes [99,99,99,30,99,99][99, 99, 99, 30, 99, 99], with a sum of 525525.