// 1. in accordance with all sections of the left point from small to large // 2 from front to back in order to enumerate each interval // First select the rightmost endpoint can cover the left end point of the interval among the right end point // in all energy covering the interval among the start, select the right end of the maximum interval // after finished selecting the start point is updated to the maximum value of the right #include <the iostream> #include <algorithm> the using namespace STD; const int N = 100010 ; int n-; struct {the Range int L, R & lt; BOOL operator <( const the Range W is &) const { return L < Wl of the; } } range[N]; int main() { int st, ed; scanf("%d%d", &st, &ed); scanf("%d", &n); for (int i = 0; i < n; i ++ ) { int l, r; scanf("%d%d", &l, &r); range[i] = {l, r}; } Sort (Range, Range + n-); int RES = 0 ; BOOL Success = to false ; for ( int I = 0 ; I <n-; I ++ ) { int J = I, R & lt = - 2E9; // find all left on the left, right interval start point is the maximum number the while (J <n-&& range [J] .L <= ST) { r = max(r, range[j].r); j ++ ; } if (r < st) { res = -1; break; } res ++ ; if (r >= ed) { success = true; break; } st = r; i = j - 1; } if (!success) res = -1; printf("%d\n", res); return 0; }