-
-
Describe
-
-
A school gate outside the length of the road is a row of trees, every two adjacent trees between the interval is 1 meters. We can think of the road as a axis, one end of the road in the position of the axis 0, the other end in the position of L; each integral point on the axis, namely 0,1,2,......,l, is planted with a tree.
There are some areas on the road to be used to build subways. These regions are represented by their starting and ending points on the axis. The coordinates of the starting and ending points of any given area are integers, and there may be overlapping parts between regions. Now the trees in these areas (including the two trees at the end of the area) are removed. Your task is to calculate how many trees there are on the road after the trees have been removed.
-
-
Input
-
The
-
first line has two integer l (1 <= L <= 10000) and M (1 <= m <=), L represents the length of the road, M represents the number of areas, and L and M are separated by a space. The next M-line contains two different integers, separated by a space, representing the coordinates of the starting and ending points of an area.
For 20% of the data, there is no overlap between the regions;
For other data, there is a overlap between the regions.
-
-
Output
-
-
includes a row that contains only an integer that represents the number of trees remaining on the road.
-
-
Sample input
-
-
500 3150 300100) 200470 471
-
-
Sample output
-
298
1#include <stdio.h>2 intMain ()3 {4 inta[10001]={0};5 intL,m,l1,l2,c=0;6scanf"%d%d",&l,&M);7 for(intI=1; i<=m;i++)8 {9scanf"%d%d",&l1,&L2);Ten for(intt=l1;t<=l2;t++) Onea[t]=1; A } - for(intI=0; i<=l;i++) - if(a[i]==0) C + +; theprintf"%d\n", c); - return 0; -}
1-6-06: Trees outside the school gate