#P16698. [CSPro 29] 施肥
[CSPro 29] 施肥
Background
Luogu’s testdata is for community exchange only and is not official testdata. Official judging link: https://www.cspro.org/.
Problem Description
Spring has come, and the fields on Xixi-Aifu Island need to be fertilized. The fields are numbered , arranged in a line in increasing order of their indices.
To fertilize the fields, Dundun prepared fertilizing trucks. However, due to different soil softness and different truck weights, not every truck can fertilize every field. Specifically, the -th truck can only exactly drive from field to field , and fertilize all fields whose indices are between and (including and ). Here, .
Dundun wants to make a fertilization plan. First, he will choose an ordered pair (), and decide to fertilize only the fields with indices between and (including and ). Then, he will choose some (or all) of the trucks to fertilize the fields. He wants to ensure that: every field with index in is fertilized at least once by some truck, and no field outside this range is fertilized.
Now he wants to know how many different ordered pairs he can choose as the fertilization range such that he can select some (or all) trucks to achieve his goal.
Input Format
Read input from standard input.
The first line contains two positive integers , representing the number of fields and the number of trucks. It is guaranteed that , .
The next lines describe the trucks. The -th line contains two positive integers , representing that the -th truck fertilizes from field to field . It is guaranteed that .
Output Format
Output to standard output.
Output one positive integer, the number of different ordered pairs that Dundun can choose as the fertilization range such that he can select some (or all) trucks to achieve his goal.
4 3
1 2
3 4
2 3
6
Hint
Explanation for Sample 1
In this sample, Dundun can choose different ordered pairs .
The first: choose , and select only the -st truck.
The second: choose , and select only the -nd truck.
The third: choose , and select only the -rd truck.
The fourth: choose , and select the -st and the -nd trucks.
The fifth: choose , and select the -st and the -rd trucks.
The sixth: choose , and select the -nd and the -rd trucks.
Sample 2
See 2.in and 2.ans in the problem directory.
This sample satisfies .
Sample 3
See 3.in and 3.ans in the problem directory.
This sample satisfies .
Sample 4
See 4.in and 4.ans in the problem directory.
This sample satisfies .
Sample 5
See 5.in and 5.ans in the problem directory.
This sample satisfies .
Sample 6
See 6.in and 6.ans in the problem directory.
This sample satisfies special property A.
Sample 7
See 7.in and 7.ans in the problem directory.
This sample satisfies .
Subtasks
| Test Point ID | Special Property | ||
|---|---|---|---|
| None | |||
| ^ | ^ | ||
| ^ | |||
| ^ | |||
| ^ | |||
| A | |||
| ^ | ^ | ||
| None | |||
| ^ | |||
Special property A: It is guaranteed that for any two trucks, their fertilization ranges do not contain each other. That is, for any , either or .
Translated by ChatGPT 5