#P1276. 校门外的树(增强版)

校门外的树(增强版)

Description

Along the road outside the school gate, positions are numbered from 00 to LL, and at every numbered position there is a tree. A lumberjack removes every tree or sapling continuously from position AA to BB inclusive (denoted as 0 A B, including AA and BB); fortunately, a planter plants a sapling at every empty hole from position CC to DD inclusive (denoted as 1 C D, including CC and DD), where an empty hole means a position where the tree has been cut and there is currently no sapling (or a previously planted sapling there has been cut again). After all operations, how many saplings remain outside the school gate? How many saplings that were planted were later cut down?

Input Format

The first line contains two positive integers LL and NN, meaning there were originally L+1L + 1 trees outside the campus, and there are NN cutting or planting operations.

Each of the following NN lines contains three integers, indicating the operation tag and its range.

Output Format

Output two lines. The first line is the number of saplings remaining outside the school gate. The second line is the number of saplings that were planted and then cut down.

10 3
0 2 6
1 1 8
0 5 7

3
2

Hint

For 100%100\% of the testdata, 1L100001 \le L \le 10000, 1N1001 \le N \le 100.

Translated by ChatGPT 5