#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll MOD = 1000000007;
ll po[200100] = {1,2,4,8,16,32,64};
struct node {
ll val, rex;
node *l, *r;
node(){val=rex=0;l=r=0;}
void pd() {
l->val *= po[rex];
l->val %= MOD;
r->val *= po[rex];
r->val %= MOD;
l->rex += rex;
r->rex += rex;
rex = 0;
}
void pu() {
val = (l->val + r->val)%MOD;
}
void init(int s, int e) {
if (s==e) {
return;
}
int m = (s+e)>>1;
l = new node();
l -> init(s,m);
r = new node();
r -> init(m+1,e);
}
void upd(int s, int e, int idx, ll v) {
if (e<idx||idx<s) return;
if (s==e) {
val += v;
val %= MOD;
return;
}
int m = (s+e)>>1;
pd();
l -> upd(s,m,idx,v);
r -> upd(m+1,e,idx,v);
pu();
}
void upde(int s, int e, int S, int E, ll ex) {
if (e<S||E<s) return;
if (S<=s&&e<=E) {
rex += ex;
val *= po[ex];
val %= MOD;
return;
}
int m = (s+e)>>1;
pd();
l -> upde(s,m,S,E,ex);
r -> upde(m+1,e,S,E,ex);
pu();
}
ll getv(int s, int e, int S, int E) {
if (e<S||E<s) return 0;
if (S<=s&&e<=E) {
return val;
}
int m = (s+e)>>1;
pd();
ll res = (l -> getv(s,m,S,E) + r -> getv(m+1,e,S,E))%MOD;
pu();
return res;
}
} *head;
int n, m;
vector<int> comp;
pii arr[200100];
bool cmpi(pii a, pii b) {
return a.second<b.second||(a.second==b.second&&a.first<b.first);
}
int main() {
int i;
scanf("%d%d",&n,&m);
comp.push_back(1);
comp.push_back(n);
for (i=0;i<m;i++) {
scanf("%d%d",&arr[i].first,&arr[i].second);
comp.push_back(arr[i].first);
comp.push_back(arr[i].second);
}
sort(comp.begin(),comp.end());
comp.erase(unique(comp.begin(),comp.end()),comp.end());
n = (int)comp.size()-1;
for (i=0;i<m;i++) {
arr[i].first = lower_bound(comp.begin(),comp.end(),arr[i].first)-comp.begin();
arr[i].second = lower_bound(comp.begin(),comp.end(),arr[i].second)-comp.begin();
}
sort(arr,arr+m,cmpi);
head = new node();
head->init(0,n);
head->upd(0,n,0,1);
for (i=0;i<m;i++) {
head->upd(0,n,arr[i].second,head->getv(0,n,arr[i].first,arr[i].second));
if (arr[i].first>0) head->upde(0,n,0,arr[i].first-1,1);
}
printf("%lld\n",head->getv(0,n,n,n));
return 0;
}
Compilation message
rail.cpp: In function 'int main()':
rail.cpp:91:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
^
rail.cpp:95:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&arr[i].first,&arr[i].second);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4360 KB |
Output is correct |
2 |
Correct |
0 ms |
4360 KB |
Output is correct |
3 |
Correct |
0 ms |
4360 KB |
Output is correct |
4 |
Correct |
0 ms |
4360 KB |
Output is correct |
5 |
Correct |
0 ms |
4360 KB |
Output is correct |
6 |
Correct |
0 ms |
4360 KB |
Output is correct |
7 |
Correct |
0 ms |
4360 KB |
Output is correct |
8 |
Correct |
0 ms |
4360 KB |
Output is correct |
9 |
Correct |
0 ms |
4360 KB |
Output is correct |
10 |
Correct |
0 ms |
4360 KB |
Output is correct |
11 |
Correct |
0 ms |
4360 KB |
Output is correct |
12 |
Correct |
0 ms |
4360 KB |
Output is correct |
13 |
Correct |
0 ms |
4360 KB |
Output is correct |
14 |
Correct |
0 ms |
4360 KB |
Output is correct |
15 |
Incorrect |
0 ms |
4360 KB |
Output isn't correct |
16 |
Correct |
0 ms |
4360 KB |
Output is correct |
17 |
Correct |
0 ms |
4360 KB |
Output is correct |
18 |
Correct |
0 ms |
4360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4360 KB |
Output is correct |
2 |
Correct |
0 ms |
4360 KB |
Output is correct |
3 |
Correct |
0 ms |
4360 KB |
Output is correct |
4 |
Correct |
0 ms |
4360 KB |
Output is correct |
5 |
Correct |
0 ms |
4360 KB |
Output is correct |
6 |
Correct |
0 ms |
4360 KB |
Output is correct |
7 |
Correct |
0 ms |
4360 KB |
Output is correct |
8 |
Correct |
0 ms |
4360 KB |
Output is correct |
9 |
Correct |
0 ms |
4360 KB |
Output is correct |
10 |
Correct |
0 ms |
4360 KB |
Output is correct |
11 |
Correct |
0 ms |
4360 KB |
Output is correct |
12 |
Correct |
0 ms |
4360 KB |
Output is correct |
13 |
Correct |
0 ms |
4360 KB |
Output is correct |
14 |
Correct |
0 ms |
4360 KB |
Output is correct |
15 |
Incorrect |
0 ms |
4360 KB |
Output isn't correct |
16 |
Correct |
0 ms |
4360 KB |
Output is correct |
17 |
Correct |
0 ms |
4360 KB |
Output is correct |
18 |
Correct |
0 ms |
4360 KB |
Output is correct |
19 |
Correct |
0 ms |
4360 KB |
Output is correct |
20 |
Correct |
0 ms |
4360 KB |
Output is correct |
21 |
Correct |
0 ms |
4360 KB |
Output is correct |
22 |
Incorrect |
0 ms |
4360 KB |
Output isn't correct |
23 |
Correct |
0 ms |
4360 KB |
Output is correct |
24 |
Correct |
0 ms |
4360 KB |
Output is correct |
25 |
Correct |
0 ms |
4360 KB |
Output is correct |
26 |
Correct |
0 ms |
4360 KB |
Output is correct |
27 |
Correct |
0 ms |
4360 KB |
Output is correct |
28 |
Correct |
0 ms |
4360 KB |
Output is correct |
29 |
Incorrect |
0 ms |
4360 KB |
Output isn't correct |
30 |
Correct |
0 ms |
4360 KB |
Output is correct |
31 |
Correct |
0 ms |
4360 KB |
Output is correct |
32 |
Correct |
0 ms |
4360 KB |
Output is correct |
33 |
Correct |
0 ms |
4360 KB |
Output is correct |
34 |
Correct |
0 ms |
4360 KB |
Output is correct |
35 |
Correct |
0 ms |
4360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4360 KB |
Output is correct |
2 |
Correct |
0 ms |
4360 KB |
Output is correct |
3 |
Correct |
0 ms |
4360 KB |
Output is correct |
4 |
Incorrect |
6 ms |
4632 KB |
Output isn't correct |
5 |
Incorrect |
293 ms |
11636 KB |
Output isn't correct |
6 |
Incorrect |
446 ms |
40808 KB |
Output isn't correct |
7 |
Incorrect |
436 ms |
40280 KB |
Output isn't correct |
8 |
Correct |
0 ms |
4360 KB |
Output is correct |
9 |
Correct |
413 ms |
38168 KB |
Output is correct |
10 |
Correct |
433 ms |
39884 KB |
Output is correct |
11 |
Incorrect |
139 ms |
8632 KB |
Output isn't correct |
12 |
Correct |
456 ms |
40808 KB |
Output is correct |
13 |
Incorrect |
426 ms |
40148 KB |
Output isn't correct |
14 |
Correct |
73 ms |
7516 KB |
Output is correct |
15 |
Correct |
399 ms |
25232 KB |
Output is correct |
16 |
Correct |
83 ms |
7516 KB |
Output is correct |
17 |
Correct |
456 ms |
40808 KB |
Output is correct |
18 |
Incorrect |
423 ms |
40808 KB |
Output isn't correct |
19 |
Incorrect |
453 ms |
35924 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4360 KB |
Output is correct |
2 |
Correct |
0 ms |
4360 KB |
Output is correct |
3 |
Correct |
0 ms |
4360 KB |
Output is correct |
4 |
Correct |
0 ms |
4360 KB |
Output is correct |
5 |
Correct |
0 ms |
4360 KB |
Output is correct |
6 |
Correct |
0 ms |
4360 KB |
Output is correct |
7 |
Correct |
0 ms |
4360 KB |
Output is correct |
8 |
Correct |
0 ms |
4360 KB |
Output is correct |
9 |
Correct |
0 ms |
4360 KB |
Output is correct |
10 |
Correct |
0 ms |
4360 KB |
Output is correct |
11 |
Correct |
0 ms |
4360 KB |
Output is correct |
12 |
Correct |
0 ms |
4360 KB |
Output is correct |
13 |
Correct |
0 ms |
4360 KB |
Output is correct |
14 |
Correct |
0 ms |
4360 KB |
Output is correct |
15 |
Incorrect |
0 ms |
4360 KB |
Output isn't correct |
16 |
Correct |
0 ms |
4360 KB |
Output is correct |
17 |
Correct |
0 ms |
4360 KB |
Output is correct |
18 |
Correct |
0 ms |
4360 KB |
Output is correct |
19 |
Correct |
0 ms |
4360 KB |
Output is correct |
20 |
Correct |
0 ms |
4360 KB |
Output is correct |
21 |
Correct |
0 ms |
4360 KB |
Output is correct |
22 |
Incorrect |
0 ms |
4360 KB |
Output isn't correct |
23 |
Correct |
0 ms |
4360 KB |
Output is correct |
24 |
Correct |
0 ms |
4360 KB |
Output is correct |
25 |
Correct |
0 ms |
4360 KB |
Output is correct |
26 |
Correct |
0 ms |
4360 KB |
Output is correct |
27 |
Correct |
0 ms |
4360 KB |
Output is correct |
28 |
Correct |
0 ms |
4360 KB |
Output is correct |
29 |
Incorrect |
0 ms |
4360 KB |
Output isn't correct |
30 |
Correct |
0 ms |
4360 KB |
Output is correct |
31 |
Correct |
0 ms |
4360 KB |
Output is correct |
32 |
Correct |
0 ms |
4360 KB |
Output is correct |
33 |
Correct |
0 ms |
4360 KB |
Output is correct |
34 |
Correct |
0 ms |
4360 KB |
Output is correct |
35 |
Correct |
0 ms |
4360 KB |
Output is correct |
36 |
Incorrect |
6 ms |
5424 KB |
Output isn't correct |
37 |
Incorrect |
9 ms |
5160 KB |
Output isn't correct |
38 |
Incorrect |
6 ms |
4764 KB |
Output isn't correct |
39 |
Incorrect |
3 ms |
4500 KB |
Output isn't correct |
40 |
Correct |
3 ms |
4896 KB |
Output is correct |
41 |
Correct |
9 ms |
5424 KB |
Output is correct |
42 |
Incorrect |
9 ms |
5424 KB |
Output isn't correct |
43 |
Correct |
0 ms |
4360 KB |
Output is correct |
44 |
Incorrect |
6 ms |
5028 KB |
Output isn't correct |
45 |
Correct |
0 ms |
4500 KB |
Output is correct |
46 |
Correct |
6 ms |
4896 KB |
Output is correct |
47 |
Incorrect |
9 ms |
4896 KB |
Output isn't correct |
48 |
Incorrect |
9 ms |
4896 KB |
Output isn't correct |
49 |
Incorrect |
3 ms |
4500 KB |
Output isn't correct |
50 |
Incorrect |
3 ms |
4500 KB |
Output isn't correct |
51 |
Incorrect |
3 ms |
4500 KB |
Output isn't correct |
52 |
Incorrect |
0 ms |
4624 KB |
Output isn't correct |
53 |
Correct |
9 ms |
5424 KB |
Output is correct |
54 |
Incorrect |
6 ms |
4632 KB |
Output isn't correct |
55 |
Correct |
9 ms |
5424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4360 KB |
Output is correct |
2 |
Correct |
0 ms |
4360 KB |
Output is correct |
3 |
Correct |
0 ms |
4360 KB |
Output is correct |
4 |
Correct |
0 ms |
4360 KB |
Output is correct |
5 |
Correct |
0 ms |
4360 KB |
Output is correct |
6 |
Correct |
0 ms |
4360 KB |
Output is correct |
7 |
Correct |
0 ms |
4360 KB |
Output is correct |
8 |
Correct |
0 ms |
4360 KB |
Output is correct |
9 |
Correct |
0 ms |
4360 KB |
Output is correct |
10 |
Correct |
0 ms |
4360 KB |
Output is correct |
11 |
Correct |
0 ms |
4360 KB |
Output is correct |
12 |
Correct |
0 ms |
4360 KB |
Output is correct |
13 |
Correct |
0 ms |
4360 KB |
Output is correct |
14 |
Correct |
0 ms |
4360 KB |
Output is correct |
15 |
Incorrect |
0 ms |
4360 KB |
Output isn't correct |
16 |
Correct |
0 ms |
4360 KB |
Output is correct |
17 |
Correct |
0 ms |
4360 KB |
Output is correct |
18 |
Correct |
0 ms |
4360 KB |
Output is correct |
19 |
Correct |
0 ms |
4360 KB |
Output is correct |
20 |
Correct |
0 ms |
4360 KB |
Output is correct |
21 |
Correct |
0 ms |
4360 KB |
Output is correct |
22 |
Incorrect |
0 ms |
4360 KB |
Output isn't correct |
23 |
Correct |
0 ms |
4360 KB |
Output is correct |
24 |
Correct |
0 ms |
4360 KB |
Output is correct |
25 |
Correct |
0 ms |
4360 KB |
Output is correct |
26 |
Correct |
0 ms |
4360 KB |
Output is correct |
27 |
Correct |
0 ms |
4360 KB |
Output is correct |
28 |
Correct |
0 ms |
4360 KB |
Output is correct |
29 |
Incorrect |
0 ms |
4360 KB |
Output isn't correct |
30 |
Correct |
0 ms |
4360 KB |
Output is correct |
31 |
Correct |
0 ms |
4360 KB |
Output is correct |
32 |
Correct |
0 ms |
4360 KB |
Output is correct |
33 |
Correct |
0 ms |
4360 KB |
Output is correct |
34 |
Correct |
0 ms |
4360 KB |
Output is correct |
35 |
Correct |
0 ms |
4360 KB |
Output is correct |
36 |
Correct |
0 ms |
4360 KB |
Output is correct |
37 |
Correct |
0 ms |
4360 KB |
Output is correct |
38 |
Correct |
0 ms |
4360 KB |
Output is correct |
39 |
Incorrect |
6 ms |
4632 KB |
Output isn't correct |
40 |
Incorrect |
293 ms |
11636 KB |
Output isn't correct |
41 |
Incorrect |
446 ms |
40808 KB |
Output isn't correct |
42 |
Incorrect |
436 ms |
40280 KB |
Output isn't correct |
43 |
Correct |
0 ms |
4360 KB |
Output is correct |
44 |
Correct |
413 ms |
38168 KB |
Output is correct |
45 |
Correct |
433 ms |
39884 KB |
Output is correct |
46 |
Incorrect |
139 ms |
8632 KB |
Output isn't correct |
47 |
Correct |
456 ms |
40808 KB |
Output is correct |
48 |
Incorrect |
426 ms |
40148 KB |
Output isn't correct |
49 |
Correct |
73 ms |
7516 KB |
Output is correct |
50 |
Correct |
399 ms |
25232 KB |
Output is correct |
51 |
Correct |
83 ms |
7516 KB |
Output is correct |
52 |
Correct |
456 ms |
40808 KB |
Output is correct |
53 |
Incorrect |
423 ms |
40808 KB |
Output isn't correct |
54 |
Incorrect |
453 ms |
35924 KB |
Output isn't correct |
55 |
Incorrect |
6 ms |
5424 KB |
Output isn't correct |
56 |
Incorrect |
9 ms |
5160 KB |
Output isn't correct |
57 |
Incorrect |
6 ms |
4764 KB |
Output isn't correct |
58 |
Incorrect |
3 ms |
4500 KB |
Output isn't correct |
59 |
Correct |
3 ms |
4896 KB |
Output is correct |
60 |
Correct |
9 ms |
5424 KB |
Output is correct |
61 |
Incorrect |
9 ms |
5424 KB |
Output isn't correct |
62 |
Correct |
0 ms |
4360 KB |
Output is correct |
63 |
Incorrect |
6 ms |
5028 KB |
Output isn't correct |
64 |
Correct |
0 ms |
4500 KB |
Output is correct |
65 |
Correct |
6 ms |
4896 KB |
Output is correct |
66 |
Incorrect |
9 ms |
4896 KB |
Output isn't correct |
67 |
Incorrect |
9 ms |
4896 KB |
Output isn't correct |
68 |
Incorrect |
3 ms |
4500 KB |
Output isn't correct |
69 |
Incorrect |
3 ms |
4500 KB |
Output isn't correct |
70 |
Incorrect |
3 ms |
4500 KB |
Output isn't correct |
71 |
Incorrect |
0 ms |
4624 KB |
Output isn't correct |
72 |
Correct |
9 ms |
5424 KB |
Output is correct |
73 |
Incorrect |
6 ms |
4632 KB |
Output isn't correct |
74 |
Correct |
9 ms |
5424 KB |
Output is correct |
75 |
Incorrect |
649 ms |
43976 KB |
Output isn't correct |
76 |
Incorrect |
413 ms |
31040 KB |
Output isn't correct |
77 |
Incorrect |
289 ms |
7516 KB |
Output isn't correct |
78 |
Incorrect |
83 ms |
7516 KB |
Output isn't correct |
79 |
Correct |
453 ms |
13616 KB |
Output is correct |
80 |
Incorrect |
676 ms |
43976 KB |
Output isn't correct |
81 |
Incorrect |
9 ms |
4896 KB |
Output isn't correct |
82 |
Incorrect |
556 ms |
39752 KB |
Output isn't correct |
83 |
Correct |
66 ms |
7516 KB |
Output is correct |
84 |
Incorrect |
479 ms |
34604 KB |
Output isn't correct |
85 |
Incorrect |
533 ms |
25100 KB |
Output isn't correct |
86 |
Incorrect |
543 ms |
25232 KB |
Output isn't correct |
87 |
Incorrect |
156 ms |
7516 KB |
Output isn't correct |
88 |
Incorrect |
159 ms |
7516 KB |
Output isn't correct |
89 |
Incorrect |
623 ms |
43976 KB |
Output isn't correct |
90 |
Incorrect |
626 ms |
43976 KB |
Output isn't correct |
91 |
Incorrect |
626 ms |
43976 KB |
Output isn't correct |
92 |
Correct |
586 ms |
42788 KB |
Output is correct |
93 |
Incorrect |
529 ms |
25100 KB |
Output isn't correct |
94 |
Incorrect |
606 ms |
43976 KB |
Output isn't correct |
95 |
Incorrect |
629 ms |
43976 KB |
Output isn't correct |