# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
66258 |
2018-08-10T06:01:23 Z |
김세빈(#1887) |
초음속철도 (OJUZ11_rail) |
C++11 |
|
777 ms |
23580 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;
const ll mod = 1e9 + 7;
pll P[202020];
vector <ll> X;
ll T[1101010], L[1101010];
ll n, m;
void init_seg(ll p, ll s, ll e)
{
L[p] = 1;
if(s == e) return;
init_seg(p << 1, s, (s + e >> 1));
init_seg(p << 1 | 1, (s + e >> 1) + 1, e);
}
void update(ll p, ll s, ll e, ll v, ll c)
{
if(s == e){
T[p] = (T[p] * L[p] + c) % mod;
L[p] = 1;
return;
}
L[p << 1] = (L[p << 1] * L[p]) % mod;
L[p << 1 | 1] = (L[p << 1 | 1] * L[p]) % mod;
if(v <= (s + e >> 1)) update(p << 1, s, (s + e >> 1), v, c);
else update(p << 1 | 1, (s + e >> 1) + 1, e, v, c);
T[p] = (T[p << 1] * L[p << 1] + T[p << 1 | 1] * L[p << 1 | 1]) % mod;
L[p] = 1;
}
void mult(ll p, ll s, ll e, ll l, ll r)
{
if(e < l || r < s) return;
if(l <= s && e <= r){
L[p] = (L[p] * 2) % mod;
return;
}
L[p << 1] = (L[p << 1] * L[p]) % mod;
L[p << 1 | 1] = (L[p << 1 | 1] * L[p]) % mod;
mult(p << 1, s, (s + e >> 1), l, r);
mult(p << 1 | 1, (s + e >> 1) + 1, e, l, r);
T[p] = (T[p << 1] * L[p << 1] + T[p << 1 | 1] * L[p << 1 | 1]) % mod;
L[p] = 1;
}
ll get_sum(ll p, ll s, ll e, ll l, ll r)
{
if(e < l || r < s) return 0;
if(l <= s && e <= r) return T[p] * L[p] % mod;
L[p << 1] = (L[p << 1] * L[p]) % mod;
L[p << 1 | 1] = (L[p << 1 | 1] * L[p]) % mod;
ll ret = get_sum(p << 1, s, (s + e >> 1), l, r);
ret = (ret + get_sum(p << 1 | 1, (s + e >> 1) + 1, e, l, r)) % mod;
T[p] = (T[p << 1] * L[p << 1] + T[p << 1 | 1] * L[p << 1 | 1]) % mod;
L[p] = 1;
return ret;
}
int main()
{
ll i, s, e;
scanf("%lld%lld", &n, &m);
X.push_back(1); X.push_back(n);
for(i=1; i<=m; i++){
scanf("%lld%lld", &s, &e);
P[i] = pll(e, s);
X.push_back(s); X.push_back(e);
}
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
n = lower_bound(X.begin(), X.end(), n) - X.begin();
sort(P + 1, P + m + 1);
init_seg(1, 0, n);
update(1, 0, n, 0, 1);
for(i=1; i<=m; i++){
e = lower_bound(X.begin(), X.end(), P[i].first) - X.begin();
s = lower_bound(X.begin(), X.end(), P[i].second) - X.begin();
mult(1, 0, n, 0, s - 1);
update(1, 0, n, e, get_sum(1, 0, n, s, e));
}
printf("%lld\n", get_sum(1, 0, n, n, n));
return 0;
}
Compilation message
rail.cpp: In function 'void init_seg(ll, ll, ll)':
rail.cpp:20:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
init_seg(p << 1, s, (s + e >> 1));
~~^~~
rail.cpp:21:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
init_seg(p << 1 | 1, (s + e >> 1) + 1, e);
~~^~~
rail.cpp: In function 'void update(ll, ll, ll, ll, ll)':
rail.cpp:35:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(v <= (s + e >> 1)) update(p << 1, s, (s + e >> 1), v, c);
~~^~~
rail.cpp:35:45: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(v <= (s + e >> 1)) update(p << 1, s, (s + e >> 1), v, c);
~~^~~
rail.cpp:36:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
else update(p << 1 | 1, (s + e >> 1) + 1, e, v, c);
~~^~~
rail.cpp: In function 'void mult(ll, ll, ll, ll, ll)':
rail.cpp:53:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mult(p << 1, s, (s + e >> 1), l, r);
~~^~~
rail.cpp:54:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mult(p << 1 | 1, (s + e >> 1) + 1, e, l, r);
~~^~~
rail.cpp: In function 'll get_sum(ll, ll, ll, ll, ll)':
rail.cpp:68:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll ret = get_sum(p << 1, s, (s + e >> 1), l, r);
~~^~~
rail.cpp:69:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ret = (ret + get_sum(p << 1 | 1, (s + e >> 1) + 1, e, l, r)) % mod;
~~^~~
rail.cpp: In function 'int main()':
rail.cpp:81:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~~~~
rail.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &s, &e);
~~~~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
436 KB |
Output is correct |
4 |
Correct |
3 ms |
436 KB |
Output is correct |
5 |
Correct |
2 ms |
436 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
480 KB |
Output is correct |
8 |
Correct |
3 ms |
608 KB |
Output is correct |
9 |
Correct |
3 ms |
608 KB |
Output is correct |
10 |
Correct |
2 ms |
608 KB |
Output is correct |
11 |
Correct |
2 ms |
608 KB |
Output is correct |
12 |
Correct |
3 ms |
692 KB |
Output is correct |
13 |
Correct |
2 ms |
692 KB |
Output is correct |
14 |
Correct |
3 ms |
692 KB |
Output is correct |
15 |
Correct |
3 ms |
692 KB |
Output is correct |
16 |
Correct |
3 ms |
692 KB |
Output is correct |
17 |
Correct |
3 ms |
692 KB |
Output is correct |
18 |
Correct |
2 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
436 KB |
Output is correct |
4 |
Correct |
3 ms |
436 KB |
Output is correct |
5 |
Correct |
2 ms |
436 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
480 KB |
Output is correct |
8 |
Correct |
3 ms |
608 KB |
Output is correct |
9 |
Correct |
3 ms |
608 KB |
Output is correct |
10 |
Correct |
2 ms |
608 KB |
Output is correct |
11 |
Correct |
2 ms |
608 KB |
Output is correct |
12 |
Correct |
3 ms |
692 KB |
Output is correct |
13 |
Correct |
2 ms |
692 KB |
Output is correct |
14 |
Correct |
3 ms |
692 KB |
Output is correct |
15 |
Correct |
3 ms |
692 KB |
Output is correct |
16 |
Correct |
3 ms |
692 KB |
Output is correct |
17 |
Correct |
3 ms |
692 KB |
Output is correct |
18 |
Correct |
2 ms |
692 KB |
Output is correct |
19 |
Correct |
3 ms |
692 KB |
Output is correct |
20 |
Correct |
2 ms |
692 KB |
Output is correct |
21 |
Correct |
2 ms |
692 KB |
Output is correct |
22 |
Correct |
2 ms |
692 KB |
Output is correct |
23 |
Correct |
2 ms |
692 KB |
Output is correct |
24 |
Correct |
3 ms |
748 KB |
Output is correct |
25 |
Correct |
2 ms |
748 KB |
Output is correct |
26 |
Correct |
2 ms |
748 KB |
Output is correct |
27 |
Correct |
2 ms |
748 KB |
Output is correct |
28 |
Correct |
2 ms |
748 KB |
Output is correct |
29 |
Correct |
2 ms |
748 KB |
Output is correct |
30 |
Correct |
2 ms |
748 KB |
Output is correct |
31 |
Correct |
2 ms |
748 KB |
Output is correct |
32 |
Correct |
3 ms |
748 KB |
Output is correct |
33 |
Correct |
2 ms |
748 KB |
Output is correct |
34 |
Correct |
2 ms |
748 KB |
Output is correct |
35 |
Correct |
2 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
748 KB |
Output is correct |
2 |
Correct |
2 ms |
748 KB |
Output is correct |
3 |
Correct |
3 ms |
748 KB |
Output is correct |
4 |
Correct |
8 ms |
892 KB |
Output is correct |
5 |
Correct |
332 ms |
9056 KB |
Output is correct |
6 |
Correct |
433 ms |
23392 KB |
Output is correct |
7 |
Correct |
419 ms |
23476 KB |
Output is correct |
8 |
Correct |
3 ms |
23476 KB |
Output is correct |
9 |
Correct |
386 ms |
23476 KB |
Output is correct |
10 |
Correct |
387 ms |
23476 KB |
Output is correct |
11 |
Correct |
167 ms |
23476 KB |
Output is correct |
12 |
Correct |
457 ms |
23476 KB |
Output is correct |
13 |
Correct |
459 ms |
23476 KB |
Output is correct |
14 |
Correct |
94 ms |
23476 KB |
Output is correct |
15 |
Correct |
418 ms |
23476 KB |
Output is correct |
16 |
Correct |
117 ms |
23476 KB |
Output is correct |
17 |
Correct |
457 ms |
23528 KB |
Output is correct |
18 |
Correct |
463 ms |
23528 KB |
Output is correct |
19 |
Correct |
461 ms |
23528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
436 KB |
Output is correct |
4 |
Correct |
3 ms |
436 KB |
Output is correct |
5 |
Correct |
2 ms |
436 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
480 KB |
Output is correct |
8 |
Correct |
3 ms |
608 KB |
Output is correct |
9 |
Correct |
3 ms |
608 KB |
Output is correct |
10 |
Correct |
2 ms |
608 KB |
Output is correct |
11 |
Correct |
2 ms |
608 KB |
Output is correct |
12 |
Correct |
3 ms |
692 KB |
Output is correct |
13 |
Correct |
2 ms |
692 KB |
Output is correct |
14 |
Correct |
3 ms |
692 KB |
Output is correct |
15 |
Correct |
3 ms |
692 KB |
Output is correct |
16 |
Correct |
3 ms |
692 KB |
Output is correct |
17 |
Correct |
3 ms |
692 KB |
Output is correct |
18 |
Correct |
2 ms |
692 KB |
Output is correct |
19 |
Correct |
3 ms |
692 KB |
Output is correct |
20 |
Correct |
2 ms |
692 KB |
Output is correct |
21 |
Correct |
2 ms |
692 KB |
Output is correct |
22 |
Correct |
2 ms |
692 KB |
Output is correct |
23 |
Correct |
2 ms |
692 KB |
Output is correct |
24 |
Correct |
3 ms |
748 KB |
Output is correct |
25 |
Correct |
2 ms |
748 KB |
Output is correct |
26 |
Correct |
2 ms |
748 KB |
Output is correct |
27 |
Correct |
2 ms |
748 KB |
Output is correct |
28 |
Correct |
2 ms |
748 KB |
Output is correct |
29 |
Correct |
2 ms |
748 KB |
Output is correct |
30 |
Correct |
2 ms |
748 KB |
Output is correct |
31 |
Correct |
2 ms |
748 KB |
Output is correct |
32 |
Correct |
3 ms |
748 KB |
Output is correct |
33 |
Correct |
2 ms |
748 KB |
Output is correct |
34 |
Correct |
2 ms |
748 KB |
Output is correct |
35 |
Correct |
2 ms |
748 KB |
Output is correct |
36 |
Correct |
12 ms |
23528 KB |
Output is correct |
37 |
Correct |
12 ms |
23528 KB |
Output is correct |
38 |
Correct |
12 ms |
23528 KB |
Output is correct |
39 |
Correct |
5 ms |
23528 KB |
Output is correct |
40 |
Correct |
11 ms |
23528 KB |
Output is correct |
41 |
Correct |
18 ms |
23528 KB |
Output is correct |
42 |
Correct |
13 ms |
23528 KB |
Output is correct |
43 |
Correct |
3 ms |
23528 KB |
Output is correct |
44 |
Correct |
9 ms |
23528 KB |
Output is correct |
45 |
Correct |
5 ms |
23528 KB |
Output is correct |
46 |
Correct |
9 ms |
23528 KB |
Output is correct |
47 |
Correct |
11 ms |
23528 KB |
Output is correct |
48 |
Correct |
10 ms |
23528 KB |
Output is correct |
49 |
Correct |
7 ms |
23528 KB |
Output is correct |
50 |
Correct |
9 ms |
23528 KB |
Output is correct |
51 |
Correct |
7 ms |
23528 KB |
Output is correct |
52 |
Correct |
5 ms |
23528 KB |
Output is correct |
53 |
Correct |
13 ms |
23528 KB |
Output is correct |
54 |
Correct |
10 ms |
23528 KB |
Output is correct |
55 |
Correct |
13 ms |
23528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
436 KB |
Output is correct |
4 |
Correct |
3 ms |
436 KB |
Output is correct |
5 |
Correct |
2 ms |
436 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
480 KB |
Output is correct |
8 |
Correct |
3 ms |
608 KB |
Output is correct |
9 |
Correct |
3 ms |
608 KB |
Output is correct |
10 |
Correct |
2 ms |
608 KB |
Output is correct |
11 |
Correct |
2 ms |
608 KB |
Output is correct |
12 |
Correct |
3 ms |
692 KB |
Output is correct |
13 |
Correct |
2 ms |
692 KB |
Output is correct |
14 |
Correct |
3 ms |
692 KB |
Output is correct |
15 |
Correct |
3 ms |
692 KB |
Output is correct |
16 |
Correct |
3 ms |
692 KB |
Output is correct |
17 |
Correct |
3 ms |
692 KB |
Output is correct |
18 |
Correct |
2 ms |
692 KB |
Output is correct |
19 |
Correct |
3 ms |
692 KB |
Output is correct |
20 |
Correct |
2 ms |
692 KB |
Output is correct |
21 |
Correct |
2 ms |
692 KB |
Output is correct |
22 |
Correct |
2 ms |
692 KB |
Output is correct |
23 |
Correct |
2 ms |
692 KB |
Output is correct |
24 |
Correct |
3 ms |
748 KB |
Output is correct |
25 |
Correct |
2 ms |
748 KB |
Output is correct |
26 |
Correct |
2 ms |
748 KB |
Output is correct |
27 |
Correct |
2 ms |
748 KB |
Output is correct |
28 |
Correct |
2 ms |
748 KB |
Output is correct |
29 |
Correct |
2 ms |
748 KB |
Output is correct |
30 |
Correct |
2 ms |
748 KB |
Output is correct |
31 |
Correct |
2 ms |
748 KB |
Output is correct |
32 |
Correct |
3 ms |
748 KB |
Output is correct |
33 |
Correct |
2 ms |
748 KB |
Output is correct |
34 |
Correct |
2 ms |
748 KB |
Output is correct |
35 |
Correct |
2 ms |
748 KB |
Output is correct |
36 |
Correct |
2 ms |
748 KB |
Output is correct |
37 |
Correct |
2 ms |
748 KB |
Output is correct |
38 |
Correct |
3 ms |
748 KB |
Output is correct |
39 |
Correct |
8 ms |
892 KB |
Output is correct |
40 |
Correct |
332 ms |
9056 KB |
Output is correct |
41 |
Correct |
433 ms |
23392 KB |
Output is correct |
42 |
Correct |
419 ms |
23476 KB |
Output is correct |
43 |
Correct |
3 ms |
23476 KB |
Output is correct |
44 |
Correct |
386 ms |
23476 KB |
Output is correct |
45 |
Correct |
387 ms |
23476 KB |
Output is correct |
46 |
Correct |
167 ms |
23476 KB |
Output is correct |
47 |
Correct |
457 ms |
23476 KB |
Output is correct |
48 |
Correct |
459 ms |
23476 KB |
Output is correct |
49 |
Correct |
94 ms |
23476 KB |
Output is correct |
50 |
Correct |
418 ms |
23476 KB |
Output is correct |
51 |
Correct |
117 ms |
23476 KB |
Output is correct |
52 |
Correct |
457 ms |
23528 KB |
Output is correct |
53 |
Correct |
463 ms |
23528 KB |
Output is correct |
54 |
Correct |
461 ms |
23528 KB |
Output is correct |
55 |
Correct |
12 ms |
23528 KB |
Output is correct |
56 |
Correct |
12 ms |
23528 KB |
Output is correct |
57 |
Correct |
12 ms |
23528 KB |
Output is correct |
58 |
Correct |
5 ms |
23528 KB |
Output is correct |
59 |
Correct |
11 ms |
23528 KB |
Output is correct |
60 |
Correct |
18 ms |
23528 KB |
Output is correct |
61 |
Correct |
13 ms |
23528 KB |
Output is correct |
62 |
Correct |
3 ms |
23528 KB |
Output is correct |
63 |
Correct |
9 ms |
23528 KB |
Output is correct |
64 |
Correct |
5 ms |
23528 KB |
Output is correct |
65 |
Correct |
9 ms |
23528 KB |
Output is correct |
66 |
Correct |
11 ms |
23528 KB |
Output is correct |
67 |
Correct |
10 ms |
23528 KB |
Output is correct |
68 |
Correct |
7 ms |
23528 KB |
Output is correct |
69 |
Correct |
9 ms |
23528 KB |
Output is correct |
70 |
Correct |
7 ms |
23528 KB |
Output is correct |
71 |
Correct |
5 ms |
23528 KB |
Output is correct |
72 |
Correct |
13 ms |
23528 KB |
Output is correct |
73 |
Correct |
10 ms |
23528 KB |
Output is correct |
74 |
Correct |
13 ms |
23528 KB |
Output is correct |
75 |
Correct |
686 ms |
23528 KB |
Output is correct |
76 |
Correct |
382 ms |
23528 KB |
Output is correct |
77 |
Correct |
304 ms |
23528 KB |
Output is correct |
78 |
Correct |
94 ms |
23528 KB |
Output is correct |
79 |
Correct |
495 ms |
23528 KB |
Output is correct |
80 |
Correct |
652 ms |
23580 KB |
Output is correct |
81 |
Correct |
11 ms |
23580 KB |
Output is correct |
82 |
Correct |
602 ms |
23580 KB |
Output is correct |
83 |
Correct |
80 ms |
23580 KB |
Output is correct |
84 |
Correct |
514 ms |
23580 KB |
Output is correct |
85 |
Correct |
586 ms |
23580 KB |
Output is correct |
86 |
Correct |
513 ms |
23580 KB |
Output is correct |
87 |
Correct |
184 ms |
23580 KB |
Output is correct |
88 |
Correct |
178 ms |
23580 KB |
Output is correct |
89 |
Correct |
635 ms |
23580 KB |
Output is correct |
90 |
Correct |
644 ms |
23580 KB |
Output is correct |
91 |
Correct |
619 ms |
23580 KB |
Output is correct |
92 |
Correct |
587 ms |
23580 KB |
Output is correct |
93 |
Correct |
556 ms |
23580 KB |
Output is correct |
94 |
Correct |
777 ms |
23580 KB |
Output is correct |
95 |
Correct |
753 ms |
23580 KB |
Output is correct |