logo AlgoBeat OnlineJudge
登录 注册

#212135. [NOISG 2025 Prelim] Snacks

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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

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

  1. Eat every snack whose deliciousness is between and (inclusive).
  2. Then, replace each eaten snack with a new snack of deliciousness .

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 of length and must process queries. Before processing any queries, print the sum of all elements in . In the -th query, update every element such that by setting , then print the updated sum of all elements in .

输入格式

Your program must read from standard input.

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

The second line of input contains space-separated integers .

The following lines of input each contain three space-separated integers. The -th of these lines contains , and , describing the -th query.

输出格式

Your program must print to standard output.

The output should contain lines.

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

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

样例

样例输入 1

5 3
1 6 2 4 6
6 6 3
2 2 3
3 3 5

样例输出 1

19
13
14
20

样例输入 2

6 4
929 121 5 3 919 72
1 133 0
70 79 0
900 999 0
1 1000 0

样例输出 2

2049
1848
1848
0
0

样例输入 3

6 5
7 72 727 123 321 9
7 9 10
10 72 727
111 222 30
123 727 99
111 222 333

样例输出 3

1259
1263
3352
3259
525
525

数据范围与提示

Subtasks

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

  • for all
  • for all
  • for all

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

Subtask Marks Additional Constraints
Sample test cases
and
No additional constraints

Sample Test Case 1 Explanation

This test case is valid for subtasks , and .

Sample Test Case 2 Explanation

This test case is valid for subtasks , and .

Sample Test Case 3 Explanation

This test case is valid for subtasks and .

Before all queries, the array a is , with a sum of .

After the first query, the array a becomes , with a sum of .

After the second query, the array a becomes , with a sum of .

After the third query, the array a becomes , with a sum of .

After the fourth query, the array a becomes , with a sum of .

After the fifth query, the array a becomes , with a sum of .