#include "bits/stdc++.h"
using namespace std;
const int MAXN = 200010;
const int MOD = 1e9 + 7;
int n, m, dp[2 * MAXN + 10];
int T[8 * MAXN], L[8 * MAXN];
pair<int,int> p[MAXN + 1];
vector<int> vx;
void init(int h, int tl, int tr) {
L[h] = 1;
if(tl == tr) return;
int mid = (tl + tr) >> 1;
init(h * 2, tl, mid);
init(h * 2 + 1, mid + 1, tr);
}
void push(int h, int tl, int tr) {
T[h] = (1ll * T[h] * L[h]) % MOD;
if(tl < tr) {
L[h * 2] = (1ll * L[h * 2] * L[h]) % MOD;
L[h * 2 + 1] = (1ll * L[h * 2 + 1] * L[h]) % MOD;
}
L[h] = 1;
}
void update1(int h, int tl, int tr, int p, int x) {
push(h, tl, tr);
if(tr < p || p < tl) return;
if(tl == tr) {
T[h] = (T[h] + x) % MOD;
} else {
int mid = (tl + tr) >> 1;
update1(h * 2, tl, mid, p, x);
update1(h * 2 + 1, mid + 1, tr, p, x);
T[h] = (T[h * 2] + T[h * 2 + 1]) % MOD;
}
}
void update2(int h, int tl, int tr, int l, int r, int x) {
push(h, tl, tr);
if(tr < l || r < tl) return;
if(l <= tl && tr <= r) {
L[h] = (1ll * L[h] * x) % MOD;
push(h, tl, tr);
} else {
int mid = (tl + tr) >> 1;
update2(h * 2, tl, mid, l, r, x);
update2(h * 2 + 1, mid + 1, tr, l, r, x);
T[h] = (T[h * 2] + T[h * 2 + 1]) % MOD;
}
}
int query(int h, int tl, int tr, int l, int r) {
push(h, tl, tr);
if(tr < l || r < tl) return 0;
if(l <= tl && tr <= r) return T[h];
int mid = (tl + tr) >> 1;
int ql = query(h * 2, tl, mid, l, r);
int qr = query(h * 2 + 1, mid + 1, tr, l, r);
return (ql + qr) % MOD;
}
int compress(int x) {
return (int)(lower_bound(vx.begin(), vx.end(), x) - vx.begin());
}
int main() {
scanf("%d%d", &n, &m);
for(int i=1; i<=m; i++) {
scanf("%d%d", &p[i].first, &p[i].second);
vx.push_back(p[i].first);
vx.push_back(p[i].second);
}
vx.push_back(1);
vx.push_back(n);
sort(vx.begin(), vx.end());
vx.erase(unique(vx.begin(), vx.end()), vx.end());
init(1, 0, vx.size() - 1);
update1(1, 0, vx.size() - 1, 0, 1);
sort(p + 1, p + m + 1);
for(int i=1; i<=m; i++) {
p[i].first = compress(p[i].first);
p[i].second = compress(p[i].second);
int qry = query(1, 0, vx.size() - 1, p[i].first, p[i].second);
update1(1, 0, vx.size() - 1, p[i].second, qry);
update2(1, 0, vx.size() - 1, p[i].second + 1, vx.size() - 1, 2);
}
printf("%d", query(1, 0, vx.size() - 1, vx.size() - 1, vx.size() - 1));
return 0;
}
Compilation message
rail.cpp: In function 'int main()':
rail.cpp:62:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
rail.cpp:64:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &p[i].first, &p[i].second);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
17644 KB |
Output is correct |
2 |
Correct |
0 ms |
17644 KB |
Output is correct |
3 |
Correct |
0 ms |
17644 KB |
Output is correct |
4 |
Correct |
0 ms |
17644 KB |
Output is correct |
5 |
Correct |
0 ms |
17644 KB |
Output is correct |
6 |
Correct |
0 ms |
17644 KB |
Output is correct |
7 |
Correct |
0 ms |
17644 KB |
Output is correct |
8 |
Correct |
0 ms |
17644 KB |
Output is correct |
9 |
Correct |
0 ms |
17644 KB |
Output is correct |
10 |
Correct |
0 ms |
17644 KB |
Output is correct |
11 |
Correct |
0 ms |
17644 KB |
Output is correct |
12 |
Correct |
0 ms |
17644 KB |
Output is correct |
13 |
Correct |
0 ms |
17644 KB |
Output is correct |
14 |
Correct |
0 ms |
17644 KB |
Output is correct |
15 |
Correct |
0 ms |
17644 KB |
Output is correct |
16 |
Correct |
0 ms |
17644 KB |
Output is correct |
17 |
Correct |
0 ms |
17644 KB |
Output is correct |
18 |
Correct |
0 ms |
17644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
17644 KB |
Output is correct |
2 |
Correct |
0 ms |
17644 KB |
Output is correct |
3 |
Correct |
0 ms |
17644 KB |
Output is correct |
4 |
Correct |
0 ms |
17644 KB |
Output is correct |
5 |
Correct |
0 ms |
17644 KB |
Output is correct |
6 |
Correct |
0 ms |
17644 KB |
Output is correct |
7 |
Correct |
0 ms |
17644 KB |
Output is correct |
8 |
Correct |
0 ms |
17644 KB |
Output is correct |
9 |
Correct |
0 ms |
17644 KB |
Output is correct |
10 |
Correct |
0 ms |
17644 KB |
Output is correct |
11 |
Correct |
0 ms |
17644 KB |
Output is correct |
12 |
Correct |
0 ms |
17644 KB |
Output is correct |
13 |
Correct |
0 ms |
17644 KB |
Output is correct |
14 |
Correct |
0 ms |
17644 KB |
Output is correct |
15 |
Correct |
0 ms |
17644 KB |
Output is correct |
16 |
Correct |
0 ms |
17644 KB |
Output is correct |
17 |
Correct |
0 ms |
17644 KB |
Output is correct |
18 |
Correct |
0 ms |
17644 KB |
Output is correct |
19 |
Correct |
0 ms |
17644 KB |
Output is correct |
20 |
Correct |
0 ms |
17644 KB |
Output is correct |
21 |
Correct |
0 ms |
17644 KB |
Output is correct |
22 |
Correct |
0 ms |
17644 KB |
Output is correct |
23 |
Correct |
0 ms |
17644 KB |
Output is correct |
24 |
Correct |
0 ms |
17644 KB |
Output is correct |
25 |
Correct |
0 ms |
17644 KB |
Output is correct |
26 |
Correct |
0 ms |
17644 KB |
Output is correct |
27 |
Correct |
0 ms |
17644 KB |
Output is correct |
28 |
Correct |
0 ms |
17644 KB |
Output is correct |
29 |
Correct |
0 ms |
17644 KB |
Output is correct |
30 |
Correct |
0 ms |
17644 KB |
Output is correct |
31 |
Correct |
0 ms |
17644 KB |
Output is correct |
32 |
Correct |
0 ms |
17644 KB |
Output is correct |
33 |
Correct |
0 ms |
17644 KB |
Output is correct |
34 |
Correct |
0 ms |
17644 KB |
Output is correct |
35 |
Correct |
0 ms |
17644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
17644 KB |
Output is correct |
2 |
Correct |
0 ms |
17644 KB |
Output is correct |
3 |
Correct |
0 ms |
17644 KB |
Output is correct |
4 |
Correct |
6 ms |
17784 KB |
Output is correct |
5 |
Correct |
349 ms |
20800 KB |
Output is correct |
6 |
Correct |
583 ms |
20800 KB |
Output is correct |
7 |
Correct |
479 ms |
20800 KB |
Output is correct |
8 |
Correct |
0 ms |
17644 KB |
Output is correct |
9 |
Correct |
443 ms |
20800 KB |
Output is correct |
10 |
Correct |
489 ms |
20800 KB |
Output is correct |
11 |
Correct |
209 ms |
19264 KB |
Output is correct |
12 |
Correct |
516 ms |
20800 KB |
Output is correct |
13 |
Correct |
509 ms |
20800 KB |
Output is correct |
14 |
Correct |
76 ms |
20800 KB |
Output is correct |
15 |
Correct |
499 ms |
20800 KB |
Output is correct |
16 |
Correct |
86 ms |
20800 KB |
Output is correct |
17 |
Correct |
519 ms |
20800 KB |
Output is correct |
18 |
Correct |
523 ms |
20800 KB |
Output is correct |
19 |
Correct |
529 ms |
20800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
17644 KB |
Output is correct |
2 |
Correct |
0 ms |
17644 KB |
Output is correct |
3 |
Correct |
0 ms |
17644 KB |
Output is correct |
4 |
Correct |
0 ms |
17644 KB |
Output is correct |
5 |
Correct |
0 ms |
17644 KB |
Output is correct |
6 |
Correct |
0 ms |
17644 KB |
Output is correct |
7 |
Correct |
0 ms |
17644 KB |
Output is correct |
8 |
Correct |
0 ms |
17644 KB |
Output is correct |
9 |
Correct |
0 ms |
17644 KB |
Output is correct |
10 |
Correct |
0 ms |
17644 KB |
Output is correct |
11 |
Correct |
0 ms |
17644 KB |
Output is correct |
12 |
Correct |
0 ms |
17644 KB |
Output is correct |
13 |
Correct |
0 ms |
17644 KB |
Output is correct |
14 |
Correct |
0 ms |
17644 KB |
Output is correct |
15 |
Correct |
0 ms |
17644 KB |
Output is correct |
16 |
Correct |
0 ms |
17644 KB |
Output is correct |
17 |
Correct |
0 ms |
17644 KB |
Output is correct |
18 |
Correct |
0 ms |
17644 KB |
Output is correct |
19 |
Correct |
0 ms |
17644 KB |
Output is correct |
20 |
Correct |
0 ms |
17644 KB |
Output is correct |
21 |
Correct |
0 ms |
17644 KB |
Output is correct |
22 |
Correct |
0 ms |
17644 KB |
Output is correct |
23 |
Correct |
0 ms |
17644 KB |
Output is correct |
24 |
Correct |
0 ms |
17644 KB |
Output is correct |
25 |
Correct |
0 ms |
17644 KB |
Output is correct |
26 |
Correct |
0 ms |
17644 KB |
Output is correct |
27 |
Correct |
0 ms |
17644 KB |
Output is correct |
28 |
Correct |
0 ms |
17644 KB |
Output is correct |
29 |
Correct |
0 ms |
17644 KB |
Output is correct |
30 |
Correct |
0 ms |
17644 KB |
Output is correct |
31 |
Correct |
0 ms |
17644 KB |
Output is correct |
32 |
Correct |
0 ms |
17644 KB |
Output is correct |
33 |
Correct |
0 ms |
17644 KB |
Output is correct |
34 |
Correct |
0 ms |
17644 KB |
Output is correct |
35 |
Correct |
0 ms |
17644 KB |
Output is correct |
36 |
Correct |
9 ms |
17784 KB |
Output is correct |
37 |
Correct |
13 ms |
17784 KB |
Output is correct |
38 |
Correct |
6 ms |
17784 KB |
Output is correct |
39 |
Correct |
0 ms |
17784 KB |
Output is correct |
40 |
Correct |
6 ms |
17784 KB |
Output is correct |
41 |
Correct |
13 ms |
17784 KB |
Output is correct |
42 |
Correct |
13 ms |
17784 KB |
Output is correct |
43 |
Correct |
0 ms |
17644 KB |
Output is correct |
44 |
Correct |
6 ms |
17784 KB |
Output is correct |
45 |
Correct |
0 ms |
17784 KB |
Output is correct |
46 |
Correct |
6 ms |
17784 KB |
Output is correct |
47 |
Correct |
6 ms |
17784 KB |
Output is correct |
48 |
Correct |
13 ms |
17784 KB |
Output is correct |
49 |
Correct |
6 ms |
17784 KB |
Output is correct |
50 |
Correct |
3 ms |
17784 KB |
Output is correct |
51 |
Correct |
3 ms |
17784 KB |
Output is correct |
52 |
Correct |
0 ms |
17644 KB |
Output is correct |
53 |
Correct |
13 ms |
17784 KB |
Output is correct |
54 |
Correct |
6 ms |
17784 KB |
Output is correct |
55 |
Correct |
9 ms |
17784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
17644 KB |
Output is correct |
2 |
Correct |
0 ms |
17644 KB |
Output is correct |
3 |
Correct |
0 ms |
17644 KB |
Output is correct |
4 |
Correct |
0 ms |
17644 KB |
Output is correct |
5 |
Correct |
0 ms |
17644 KB |
Output is correct |
6 |
Correct |
0 ms |
17644 KB |
Output is correct |
7 |
Correct |
0 ms |
17644 KB |
Output is correct |
8 |
Correct |
0 ms |
17644 KB |
Output is correct |
9 |
Correct |
0 ms |
17644 KB |
Output is correct |
10 |
Correct |
0 ms |
17644 KB |
Output is correct |
11 |
Correct |
0 ms |
17644 KB |
Output is correct |
12 |
Correct |
0 ms |
17644 KB |
Output is correct |
13 |
Correct |
0 ms |
17644 KB |
Output is correct |
14 |
Correct |
0 ms |
17644 KB |
Output is correct |
15 |
Correct |
0 ms |
17644 KB |
Output is correct |
16 |
Correct |
0 ms |
17644 KB |
Output is correct |
17 |
Correct |
0 ms |
17644 KB |
Output is correct |
18 |
Correct |
0 ms |
17644 KB |
Output is correct |
19 |
Correct |
0 ms |
17644 KB |
Output is correct |
20 |
Correct |
0 ms |
17644 KB |
Output is correct |
21 |
Correct |
0 ms |
17644 KB |
Output is correct |
22 |
Correct |
0 ms |
17644 KB |
Output is correct |
23 |
Correct |
0 ms |
17644 KB |
Output is correct |
24 |
Correct |
0 ms |
17644 KB |
Output is correct |
25 |
Correct |
0 ms |
17644 KB |
Output is correct |
26 |
Correct |
0 ms |
17644 KB |
Output is correct |
27 |
Correct |
0 ms |
17644 KB |
Output is correct |
28 |
Correct |
0 ms |
17644 KB |
Output is correct |
29 |
Correct |
0 ms |
17644 KB |
Output is correct |
30 |
Correct |
0 ms |
17644 KB |
Output is correct |
31 |
Correct |
0 ms |
17644 KB |
Output is correct |
32 |
Correct |
0 ms |
17644 KB |
Output is correct |
33 |
Correct |
0 ms |
17644 KB |
Output is correct |
34 |
Correct |
0 ms |
17644 KB |
Output is correct |
35 |
Correct |
0 ms |
17644 KB |
Output is correct |
36 |
Correct |
0 ms |
17644 KB |
Output is correct |
37 |
Correct |
0 ms |
17644 KB |
Output is correct |
38 |
Correct |
0 ms |
17644 KB |
Output is correct |
39 |
Correct |
6 ms |
17784 KB |
Output is correct |
40 |
Correct |
349 ms |
20800 KB |
Output is correct |
41 |
Correct |
583 ms |
20800 KB |
Output is correct |
42 |
Correct |
479 ms |
20800 KB |
Output is correct |
43 |
Correct |
0 ms |
17644 KB |
Output is correct |
44 |
Correct |
443 ms |
20800 KB |
Output is correct |
45 |
Correct |
489 ms |
20800 KB |
Output is correct |
46 |
Correct |
209 ms |
19264 KB |
Output is correct |
47 |
Correct |
516 ms |
20800 KB |
Output is correct |
48 |
Correct |
509 ms |
20800 KB |
Output is correct |
49 |
Correct |
76 ms |
20800 KB |
Output is correct |
50 |
Correct |
499 ms |
20800 KB |
Output is correct |
51 |
Correct |
86 ms |
20800 KB |
Output is correct |
52 |
Correct |
519 ms |
20800 KB |
Output is correct |
53 |
Correct |
523 ms |
20800 KB |
Output is correct |
54 |
Correct |
529 ms |
20800 KB |
Output is correct |
55 |
Correct |
9 ms |
17784 KB |
Output is correct |
56 |
Correct |
13 ms |
17784 KB |
Output is correct |
57 |
Correct |
6 ms |
17784 KB |
Output is correct |
58 |
Correct |
0 ms |
17784 KB |
Output is correct |
59 |
Correct |
6 ms |
17784 KB |
Output is correct |
60 |
Correct |
13 ms |
17784 KB |
Output is correct |
61 |
Correct |
13 ms |
17784 KB |
Output is correct |
62 |
Correct |
0 ms |
17644 KB |
Output is correct |
63 |
Correct |
6 ms |
17784 KB |
Output is correct |
64 |
Correct |
0 ms |
17784 KB |
Output is correct |
65 |
Correct |
6 ms |
17784 KB |
Output is correct |
66 |
Correct |
6 ms |
17784 KB |
Output is correct |
67 |
Correct |
13 ms |
17784 KB |
Output is correct |
68 |
Correct |
6 ms |
17784 KB |
Output is correct |
69 |
Correct |
3 ms |
17784 KB |
Output is correct |
70 |
Correct |
3 ms |
17784 KB |
Output is correct |
71 |
Correct |
0 ms |
17644 KB |
Output is correct |
72 |
Correct |
13 ms |
17784 KB |
Output is correct |
73 |
Correct |
6 ms |
17784 KB |
Output is correct |
74 |
Correct |
9 ms |
17784 KB |
Output is correct |
75 |
Correct |
759 ms |
20800 KB |
Output is correct |
76 |
Correct |
506 ms |
20800 KB |
Output is correct |
77 |
Correct |
379 ms |
20800 KB |
Output is correct |
78 |
Correct |
99 ms |
20800 KB |
Output is correct |
79 |
Correct |
549 ms |
20800 KB |
Output is correct |
80 |
Correct |
733 ms |
20800 KB |
Output is correct |
81 |
Correct |
9 ms |
17784 KB |
Output is correct |
82 |
Correct |
659 ms |
20800 KB |
Output is correct |
83 |
Correct |
63 ms |
20800 KB |
Output is correct |
84 |
Correct |
559 ms |
20800 KB |
Output is correct |
85 |
Correct |
669 ms |
20800 KB |
Output is correct |
86 |
Correct |
669 ms |
20800 KB |
Output is correct |
87 |
Correct |
246 ms |
20800 KB |
Output is correct |
88 |
Correct |
219 ms |
20800 KB |
Output is correct |
89 |
Correct |
806 ms |
20800 KB |
Output is correct |
90 |
Correct |
843 ms |
20800 KB |
Output is correct |
91 |
Correct |
816 ms |
20800 KB |
Output is correct |
92 |
Correct |
766 ms |
20800 KB |
Output is correct |
93 |
Correct |
713 ms |
20800 KB |
Output is correct |
94 |
Correct |
819 ms |
20800 KB |
Output is correct |
95 |
Correct |
803 ms |
20800 KB |
Output is correct |