#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll m, n, two[200005], sz;
pair<ll,ll> a[200005];
vector<ll> cpr;
struct segtree {
ll val[1111111], lazy[1111111];
void lazydown (ll P) {
val[2*P] = (val[2*P] * two[lazy[P]]) % mod;
lazy[2*P] += lazy[P];
val[2*P+1] = (val[2*P+1] * two[lazy[P]]) % mod;
lazy[2*P+1] += lazy[P];
lazy[P] = 0;
}
void pl (ll SS, ll SE, ll X, ll P, ll V) {
if(SE < X || X < SS) return;
if(SS == SE) {val[P] += V; return;}
lazydown(P);
ll mid = (SS+SE)/2;
pl(SS, mid, X, 2*P, V);
pl(mid+1, SE, X, 2*P+1, V);
val[P] = (val[2*P] + val[2*P+1]) % mod;
}
void pl(ll X, ll V) {pl(0, sz-1, X, 1, V);}
void ml (ll SS, ll SE, ll S, ll E, ll P, ll V) {
if(S <= SS && SE <= E) {
val[P] = (val[P] * two[V]) % mod;
lazy[P] += V;
return;
}
if(SE < S || E < SS) return;
lazydown(P);
ll mid = (SS+SE)/2;
ml(SS, mid, S, E, 2*P, V);
ml(mid+1, SE, S, E, 2*P+1, V);
val[P] = (val[2*P] + val[2*P+1]) % mod;
}
void ml (ll S, ll E, ll V) {ml(0, sz-1, S, E, 1, V);}
ll query (ll SS, ll SE, ll S, ll E, ll P) {
if(S <= SS && SE <= E) return val[P];
if(SE < S || E < SS) return 0;
lazydown(P);
ll mid = (SS+SE)/2;
return (query(SS, mid, S, E, 2*P) +
query(mid+1, SE, S, E, 2*P+1)) % mod;
}
ll query (ll S, ll E) {return query(0, sz-1, S, E, 1);}
} seg;
int main()
{
scanf("%lld%lld",&m,&n);
two[0] = 1;
for(int i=1;i<=n;i++) {
two[i] = (two[i-1] * 2) % mod;
}
for(int i=1;i<=n;i++) {
scanf("%lld%lld",&a[i].X,&a[i].Y);
cpr.push_back(a[i].X);
cpr.push_back(a[i].Y);
}
sort(cpr.begin(), cpr.end());
cpr.erase(unique(cpr.begin(), cpr.end()), cpr.end());
if(cpr[0] != 1 || cpr.back() != m) {puts("0"); return 0;}
for(int i=1;i<=n;i++) {
a[i].X = lower_bound(cpr.begin(), cpr.end(), a[i].X) - cpr.begin();
a[i].Y = lower_bound(cpr.begin(), cpr.end(), a[i].Y) - cpr.begin();
}
sort(a+1, a+1+n);
sz = cpr.size();
seg.pl(0, 1);
for(int i=1;i<=n;i++) {
seg.pl(a[i].Y, seg.query(a[i].X, a[i].Y));
seg.ml(a[i].Y+1, sz-1, 1);
}
printf("%lld\n",seg.query(sz-1, sz-1));
}
Compilation message
rail.cpp: In function 'int main()':
rail.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&m,&n);
~~~~~^~~~~~~~~~~~~~~~~~
rail.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&a[i].X,&a[i].Y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
444 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
3 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
708 KB |
Output is correct |
7 |
Correct |
2 ms |
708 KB |
Output is correct |
8 |
Correct |
3 ms |
708 KB |
Output is correct |
9 |
Correct |
3 ms |
708 KB |
Output is correct |
10 |
Correct |
2 ms |
708 KB |
Output is correct |
11 |
Correct |
2 ms |
708 KB |
Output is correct |
12 |
Correct |
3 ms |
708 KB |
Output is correct |
13 |
Correct |
3 ms |
708 KB |
Output is correct |
14 |
Correct |
2 ms |
708 KB |
Output is correct |
15 |
Correct |
2 ms |
708 KB |
Output is correct |
16 |
Correct |
2 ms |
708 KB |
Output is correct |
17 |
Correct |
2 ms |
708 KB |
Output is correct |
18 |
Correct |
2 ms |
708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
444 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
3 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
708 KB |
Output is correct |
7 |
Correct |
2 ms |
708 KB |
Output is correct |
8 |
Correct |
3 ms |
708 KB |
Output is correct |
9 |
Correct |
3 ms |
708 KB |
Output is correct |
10 |
Correct |
2 ms |
708 KB |
Output is correct |
11 |
Correct |
2 ms |
708 KB |
Output is correct |
12 |
Correct |
3 ms |
708 KB |
Output is correct |
13 |
Correct |
3 ms |
708 KB |
Output is correct |
14 |
Correct |
2 ms |
708 KB |
Output is correct |
15 |
Correct |
2 ms |
708 KB |
Output is correct |
16 |
Correct |
2 ms |
708 KB |
Output is correct |
17 |
Correct |
2 ms |
708 KB |
Output is correct |
18 |
Correct |
2 ms |
708 KB |
Output is correct |
19 |
Correct |
2 ms |
708 KB |
Output is correct |
20 |
Correct |
2 ms |
708 KB |
Output is correct |
21 |
Correct |
2 ms |
708 KB |
Output is correct |
22 |
Correct |
3 ms |
708 KB |
Output is correct |
23 |
Correct |
2 ms |
708 KB |
Output is correct |
24 |
Correct |
2 ms |
712 KB |
Output is correct |
25 |
Correct |
2 ms |
716 KB |
Output is correct |
26 |
Correct |
2 ms |
828 KB |
Output is correct |
27 |
Correct |
3 ms |
828 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Correct |
2 ms |
856 KB |
Output is correct |
30 |
Correct |
2 ms |
856 KB |
Output is correct |
31 |
Correct |
2 ms |
856 KB |
Output is correct |
32 |
Correct |
3 ms |
856 KB |
Output is correct |
33 |
Correct |
3 ms |
856 KB |
Output is correct |
34 |
Correct |
2 ms |
856 KB |
Output is correct |
35 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
856 KB |
Output is correct |
3 |
Correct |
2 ms |
856 KB |
Output is correct |
4 |
Correct |
8 ms |
1172 KB |
Output is correct |
5 |
Correct |
284 ms |
10948 KB |
Output is correct |
6 |
Correct |
482 ms |
25328 KB |
Output is correct |
7 |
Correct |
424 ms |
25364 KB |
Output is correct |
8 |
Correct |
2 ms |
25364 KB |
Output is correct |
9 |
Correct |
434 ms |
25364 KB |
Output is correct |
10 |
Correct |
421 ms |
25364 KB |
Output is correct |
11 |
Correct |
178 ms |
25364 KB |
Output is correct |
12 |
Correct |
474 ms |
25368 KB |
Output is correct |
13 |
Correct |
465 ms |
25368 KB |
Output is correct |
14 |
Correct |
89 ms |
25368 KB |
Output is correct |
15 |
Correct |
572 ms |
25368 KB |
Output is correct |
16 |
Correct |
97 ms |
25368 KB |
Output is correct |
17 |
Correct |
459 ms |
25368 KB |
Output is correct |
18 |
Correct |
445 ms |
25376 KB |
Output is correct |
19 |
Correct |
438 ms |
25376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
444 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
3 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
708 KB |
Output is correct |
7 |
Correct |
2 ms |
708 KB |
Output is correct |
8 |
Correct |
3 ms |
708 KB |
Output is correct |
9 |
Correct |
3 ms |
708 KB |
Output is correct |
10 |
Correct |
2 ms |
708 KB |
Output is correct |
11 |
Correct |
2 ms |
708 KB |
Output is correct |
12 |
Correct |
3 ms |
708 KB |
Output is correct |
13 |
Correct |
3 ms |
708 KB |
Output is correct |
14 |
Correct |
2 ms |
708 KB |
Output is correct |
15 |
Correct |
2 ms |
708 KB |
Output is correct |
16 |
Correct |
2 ms |
708 KB |
Output is correct |
17 |
Correct |
2 ms |
708 KB |
Output is correct |
18 |
Correct |
2 ms |
708 KB |
Output is correct |
19 |
Correct |
2 ms |
708 KB |
Output is correct |
20 |
Correct |
2 ms |
708 KB |
Output is correct |
21 |
Correct |
2 ms |
708 KB |
Output is correct |
22 |
Correct |
3 ms |
708 KB |
Output is correct |
23 |
Correct |
2 ms |
708 KB |
Output is correct |
24 |
Correct |
2 ms |
712 KB |
Output is correct |
25 |
Correct |
2 ms |
716 KB |
Output is correct |
26 |
Correct |
2 ms |
828 KB |
Output is correct |
27 |
Correct |
3 ms |
828 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Correct |
2 ms |
856 KB |
Output is correct |
30 |
Correct |
2 ms |
856 KB |
Output is correct |
31 |
Correct |
2 ms |
856 KB |
Output is correct |
32 |
Correct |
3 ms |
856 KB |
Output is correct |
33 |
Correct |
3 ms |
856 KB |
Output is correct |
34 |
Correct |
2 ms |
856 KB |
Output is correct |
35 |
Correct |
2 ms |
856 KB |
Output is correct |
36 |
Correct |
13 ms |
25376 KB |
Output is correct |
37 |
Correct |
12 ms |
25376 KB |
Output is correct |
38 |
Correct |
9 ms |
25376 KB |
Output is correct |
39 |
Correct |
5 ms |
25376 KB |
Output is correct |
40 |
Correct |
11 ms |
25376 KB |
Output is correct |
41 |
Correct |
4 ms |
25376 KB |
Output is correct |
42 |
Correct |
13 ms |
25376 KB |
Output is correct |
43 |
Correct |
2 ms |
25376 KB |
Output is correct |
44 |
Correct |
11 ms |
25376 KB |
Output is correct |
45 |
Correct |
4 ms |
25376 KB |
Output is correct |
46 |
Correct |
12 ms |
25376 KB |
Output is correct |
47 |
Correct |
10 ms |
25376 KB |
Output is correct |
48 |
Correct |
10 ms |
25376 KB |
Output is correct |
49 |
Correct |
6 ms |
25376 KB |
Output is correct |
50 |
Correct |
7 ms |
25376 KB |
Output is correct |
51 |
Correct |
6 ms |
25376 KB |
Output is correct |
52 |
Correct |
5 ms |
25376 KB |
Output is correct |
53 |
Correct |
6 ms |
25376 KB |
Output is correct |
54 |
Correct |
10 ms |
25376 KB |
Output is correct |
55 |
Correct |
5 ms |
25376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
444 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
3 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
708 KB |
Output is correct |
7 |
Correct |
2 ms |
708 KB |
Output is correct |
8 |
Correct |
3 ms |
708 KB |
Output is correct |
9 |
Correct |
3 ms |
708 KB |
Output is correct |
10 |
Correct |
2 ms |
708 KB |
Output is correct |
11 |
Correct |
2 ms |
708 KB |
Output is correct |
12 |
Correct |
3 ms |
708 KB |
Output is correct |
13 |
Correct |
3 ms |
708 KB |
Output is correct |
14 |
Correct |
2 ms |
708 KB |
Output is correct |
15 |
Correct |
2 ms |
708 KB |
Output is correct |
16 |
Correct |
2 ms |
708 KB |
Output is correct |
17 |
Correct |
2 ms |
708 KB |
Output is correct |
18 |
Correct |
2 ms |
708 KB |
Output is correct |
19 |
Correct |
2 ms |
708 KB |
Output is correct |
20 |
Correct |
2 ms |
708 KB |
Output is correct |
21 |
Correct |
2 ms |
708 KB |
Output is correct |
22 |
Correct |
3 ms |
708 KB |
Output is correct |
23 |
Correct |
2 ms |
708 KB |
Output is correct |
24 |
Correct |
2 ms |
712 KB |
Output is correct |
25 |
Correct |
2 ms |
716 KB |
Output is correct |
26 |
Correct |
2 ms |
828 KB |
Output is correct |
27 |
Correct |
3 ms |
828 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Correct |
2 ms |
856 KB |
Output is correct |
30 |
Correct |
2 ms |
856 KB |
Output is correct |
31 |
Correct |
2 ms |
856 KB |
Output is correct |
32 |
Correct |
3 ms |
856 KB |
Output is correct |
33 |
Correct |
3 ms |
856 KB |
Output is correct |
34 |
Correct |
2 ms |
856 KB |
Output is correct |
35 |
Correct |
2 ms |
856 KB |
Output is correct |
36 |
Correct |
3 ms |
856 KB |
Output is correct |
37 |
Correct |
2 ms |
856 KB |
Output is correct |
38 |
Correct |
2 ms |
856 KB |
Output is correct |
39 |
Correct |
8 ms |
1172 KB |
Output is correct |
40 |
Correct |
284 ms |
10948 KB |
Output is correct |
41 |
Correct |
482 ms |
25328 KB |
Output is correct |
42 |
Correct |
424 ms |
25364 KB |
Output is correct |
43 |
Correct |
2 ms |
25364 KB |
Output is correct |
44 |
Correct |
434 ms |
25364 KB |
Output is correct |
45 |
Correct |
421 ms |
25364 KB |
Output is correct |
46 |
Correct |
178 ms |
25364 KB |
Output is correct |
47 |
Correct |
474 ms |
25368 KB |
Output is correct |
48 |
Correct |
465 ms |
25368 KB |
Output is correct |
49 |
Correct |
89 ms |
25368 KB |
Output is correct |
50 |
Correct |
572 ms |
25368 KB |
Output is correct |
51 |
Correct |
97 ms |
25368 KB |
Output is correct |
52 |
Correct |
459 ms |
25368 KB |
Output is correct |
53 |
Correct |
445 ms |
25376 KB |
Output is correct |
54 |
Correct |
438 ms |
25376 KB |
Output is correct |
55 |
Correct |
13 ms |
25376 KB |
Output is correct |
56 |
Correct |
12 ms |
25376 KB |
Output is correct |
57 |
Correct |
9 ms |
25376 KB |
Output is correct |
58 |
Correct |
5 ms |
25376 KB |
Output is correct |
59 |
Correct |
11 ms |
25376 KB |
Output is correct |
60 |
Correct |
4 ms |
25376 KB |
Output is correct |
61 |
Correct |
13 ms |
25376 KB |
Output is correct |
62 |
Correct |
2 ms |
25376 KB |
Output is correct |
63 |
Correct |
11 ms |
25376 KB |
Output is correct |
64 |
Correct |
4 ms |
25376 KB |
Output is correct |
65 |
Correct |
12 ms |
25376 KB |
Output is correct |
66 |
Correct |
10 ms |
25376 KB |
Output is correct |
67 |
Correct |
10 ms |
25376 KB |
Output is correct |
68 |
Correct |
6 ms |
25376 KB |
Output is correct |
69 |
Correct |
7 ms |
25376 KB |
Output is correct |
70 |
Correct |
6 ms |
25376 KB |
Output is correct |
71 |
Correct |
5 ms |
25376 KB |
Output is correct |
72 |
Correct |
6 ms |
25376 KB |
Output is correct |
73 |
Correct |
10 ms |
25376 KB |
Output is correct |
74 |
Correct |
5 ms |
25376 KB |
Output is correct |
75 |
Correct |
657 ms |
25376 KB |
Output is correct |
76 |
Correct |
381 ms |
25376 KB |
Output is correct |
77 |
Correct |
301 ms |
25376 KB |
Output is correct |
78 |
Correct |
95 ms |
25376 KB |
Output is correct |
79 |
Correct |
107 ms |
25376 KB |
Output is correct |
80 |
Correct |
616 ms |
25376 KB |
Output is correct |
81 |
Correct |
12 ms |
25376 KB |
Output is correct |
82 |
Correct |
576 ms |
25376 KB |
Output is correct |
83 |
Correct |
79 ms |
25376 KB |
Output is correct |
84 |
Correct |
482 ms |
25412 KB |
Output is correct |
85 |
Correct |
524 ms |
25412 KB |
Output is correct |
86 |
Correct |
543 ms |
25412 KB |
Output is correct |
87 |
Correct |
173 ms |
25412 KB |
Output is correct |
88 |
Correct |
163 ms |
25412 KB |
Output is correct |
89 |
Correct |
623 ms |
25412 KB |
Output is correct |
90 |
Correct |
632 ms |
25412 KB |
Output is correct |
91 |
Correct |
660 ms |
25412 KB |
Output is correct |
92 |
Correct |
116 ms |
25412 KB |
Output is correct |
93 |
Correct |
565 ms |
25412 KB |
Output is correct |
94 |
Correct |
656 ms |
25412 KB |
Output is correct |
95 |
Correct |
669 ms |
25412 KB |
Output is correct |