题库练习 Addition on Segments
← 上一题 下一题 →

A11856 | Addition on Segments

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Grisha come to a contest and faced the following problem.

You are given an array of size $n$ , initially consisting of zeros. The elements of the array are enumerated from $1$ to $n$ . You perform $q$ operations on the array. The $i$ -th operation is described with three integers $l_i$ , $r_i$ and $x_i$ ( $1 \leq l_i \leq r_i \leq n$ , $1 \leq x_i \leq n$ ) and means that you should add $x_i$ to each of the elements with indices $l_i, l_i + 1, \ldots, r_i$ . After all operations you should find the maximum in the array.

Grisha is clever, so he solved the problem quickly.

However something went wrong inside his head and now he thinks of the following question: "consider we applied some subset of the operations to the array. What are the possible values of the maximum in the array?"

Help Grisha, find all integers $y$ between $1$ and $n$ such that if you apply some subset (possibly empty) of the operations, then the maximum in the array becomes equal to $y$ .

输入格式

The first line contains two integers $n$ and $q$ ( $1 \leq n, q \leq 10^{4}$ ) — the length of the array and the number of queries in the initial problem.

The following $q$ lines contain queries, one per line. The $i$ -th of these lines contains three integers $l_i$ , $r_i$ and $x_i$ ( $1 \leq l_i \leq r_i \leq n$ , $1 \leq x_i \leq n$ ), denoting a query of adding $x_i$ to the segment from $l_i$ -th to $r_i$ -th elements of the array, inclusive.

输出格式

In the first line print the only integer $k$ , denoting the number of integers from $1$ to $n$ , inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations.

In the next line print these $k$ integers from $1$ to $n$ — the possible values of the maximum. Print these integers in increasing order.

输入输出样例

输入 #1
4 3
1 3 1
2 4 2
3 4 4
输出 #1
4
1 2 3 4 
输入 #2
7 2
1 5 1
3 7 2
输出 #2
3
1 2 3 
输入 #3
10 3
1 1 2
1 1 3
1 1 6
输出 #3
6
2 3 5 6 8 9 
C++ 编辑器
输入
输出