# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
164039 |
2019-11-17T06:42:53 Z |
xtalxlr |
초음속철도 (OJUZ11_rail) |
C++17 |
|
914 ms |
133044 KB |
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const ll mod = 1000000007LL;
const int N = 2000050;
ll mul[4*N], tot[4*N];
void init() {
for (int i = 0; i < 4*N; i++) {
mul[i] = 1LL;
tot[i] = 0LL;
}
}
void propagate(int i, int st, int ed) {
tot[i] = (tot[i] * mul[i]) % mod;
int li = 2*i+1, ri = 2*i+2;
if (ed - st > 1) {
mul[li] = mul[li] * mul[i] % mod;
mul[ri] = mul[ri] * mul[i] % mod;
}
mul[i] = 1LL;
}
void q_mul(ll val, int q_st, int q_ed, int i=0, int st=0, int ed=N) {
if (q_st == st && q_ed == ed) {
mul[i] = mul[i] * val % mod;
} else {
propagate(i, st, ed);
int md = st + (ed - st) / 2;
if (q_st < md)
q_mul(val, q_st, min(q_ed, md), 2*i+1, st, md);
propagate(2*i+1, st, md);
if (md < q_ed)
q_mul(val, max(q_st, md), q_ed, 2*i+2, md, ed);
propagate(2*i+2, md, ed);
tot[i] = (tot[2*i+1] + tot[2*i+2]) % mod;
}
}
void q_add(ll val, int qi, int i=0, int st=0, int ed=N) {
if (st == qi && ed == qi + 1) {
propagate(i, st, ed);
tot[i] = (tot[i] + val) % mod;
} else {
propagate(i, st, ed);
int md = st + (ed - st) / 2;
if (qi < md)
q_add(val, qi, 2*i+1, st, md);
else
q_add(val, qi, 2*i+2, md, ed);
tot[i] = (tot[2*i+1] + tot[2*i+2]) % mod;
}
}
ll q_sum(int q_st, int q_ed, int i=0, int st=0, int ed=N) {
if (q_st == st && q_ed == ed) {
propagate(i, st, ed);
return tot[i];
} else {
propagate(i, st, ed);
ll res = 0LL;
int md = st + (ed - st) / 2;
if (q_st < md)
res += q_sum(q_st, min(q_ed, md), 2*i+1, st, md);
if (md < q_ed)
res += q_sum(max(q_st, md), q_ed, 2*i+2, md, ed);
return res;
}
}
int n;
vector< pair<int, int> > p;
int main() {
int last;
scanf("%d %d", &last, &n);
vector<int> vals;
vals.push_back(1);
vals.push_back(last);
for (int i = 0; i < n; i++) {
int s, e;
scanf("%d %d", &s, &e);
vals.push_back(s);
vals.push_back(e);
p.emplace_back(s, e);
}
sort(vals.begin(), vals.end());
vals.resize(unique(vals.begin(), vals.end()) - vals.begin());
for (auto &pr : p) {
pr.first = lower_bound(vals.begin(), vals.end(), pr.first) - vals.begin();
pr.second = lower_bound(vals.begin(), vals.end(), pr.second) - vals.begin();
}
sort(p.begin(), p.end(), [](const pii &p1, const pii &p2) {
return p1.second < p2.second;
});
init();
q_add(1, 0);
for (auto &pr : p) {
int st = pr.first;
int ed = pr.second;
// printf("%d %d\n", st, ed);
if (st > 0)
q_mul(2LL, 0, st);
ll s = q_sum(st, ed + 1);
// printf("%lld\n", s);
q_add(s, ed); // q_add(ed, s);
/*
for (int i = 0; i < 5; i++)
printf("%lld ", q_sum(i, i + 1));
printf("\n");
*/
}
int lval = int(vals.size()) - 1;
// printf("%d\n", lval);
printf("%lld\n", q_sum(lval, lval + 1));
return 0;
}
Compilation message
rail.cpp: In function 'int main()':
rail.cpp:82:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &last, &n);
~~~~~^~~~~~~~~~~~~~~~~~~~
rail.cpp:88:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &s, &e);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
125560 KB |
Output is correct |
2 |
Correct |
119 ms |
125560 KB |
Output is correct |
3 |
Correct |
118 ms |
125688 KB |
Output is correct |
4 |
Correct |
117 ms |
125560 KB |
Output is correct |
5 |
Correct |
113 ms |
125560 KB |
Output is correct |
6 |
Correct |
115 ms |
125492 KB |
Output is correct |
7 |
Correct |
117 ms |
125544 KB |
Output is correct |
8 |
Correct |
112 ms |
125560 KB |
Output is correct |
9 |
Correct |
119 ms |
125624 KB |
Output is correct |
10 |
Correct |
119 ms |
125632 KB |
Output is correct |
11 |
Correct |
119 ms |
125560 KB |
Output is correct |
12 |
Correct |
117 ms |
125560 KB |
Output is correct |
13 |
Correct |
117 ms |
125576 KB |
Output is correct |
14 |
Correct |
120 ms |
125560 KB |
Output is correct |
15 |
Correct |
117 ms |
125612 KB |
Output is correct |
16 |
Correct |
118 ms |
125560 KB |
Output is correct |
17 |
Correct |
120 ms |
125544 KB |
Output is correct |
18 |
Correct |
116 ms |
125560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
125560 KB |
Output is correct |
2 |
Correct |
119 ms |
125560 KB |
Output is correct |
3 |
Correct |
118 ms |
125688 KB |
Output is correct |
4 |
Correct |
117 ms |
125560 KB |
Output is correct |
5 |
Correct |
113 ms |
125560 KB |
Output is correct |
6 |
Correct |
115 ms |
125492 KB |
Output is correct |
7 |
Correct |
117 ms |
125544 KB |
Output is correct |
8 |
Correct |
112 ms |
125560 KB |
Output is correct |
9 |
Correct |
119 ms |
125624 KB |
Output is correct |
10 |
Correct |
119 ms |
125632 KB |
Output is correct |
11 |
Correct |
119 ms |
125560 KB |
Output is correct |
12 |
Correct |
117 ms |
125560 KB |
Output is correct |
13 |
Correct |
117 ms |
125576 KB |
Output is correct |
14 |
Correct |
120 ms |
125560 KB |
Output is correct |
15 |
Correct |
117 ms |
125612 KB |
Output is correct |
16 |
Correct |
118 ms |
125560 KB |
Output is correct |
17 |
Correct |
120 ms |
125544 KB |
Output is correct |
18 |
Correct |
116 ms |
125560 KB |
Output is correct |
19 |
Correct |
116 ms |
125596 KB |
Output is correct |
20 |
Correct |
114 ms |
125564 KB |
Output is correct |
21 |
Correct |
118 ms |
125560 KB |
Output is correct |
22 |
Correct |
119 ms |
125560 KB |
Output is correct |
23 |
Correct |
118 ms |
125556 KB |
Output is correct |
24 |
Correct |
118 ms |
125572 KB |
Output is correct |
25 |
Correct |
119 ms |
125496 KB |
Output is correct |
26 |
Correct |
119 ms |
125560 KB |
Output is correct |
27 |
Correct |
119 ms |
125560 KB |
Output is correct |
28 |
Correct |
118 ms |
125564 KB |
Output is correct |
29 |
Correct |
117 ms |
125564 KB |
Output is correct |
30 |
Correct |
118 ms |
125560 KB |
Output is correct |
31 |
Correct |
117 ms |
125588 KB |
Output is correct |
32 |
Correct |
118 ms |
125532 KB |
Output is correct |
33 |
Correct |
116 ms |
125548 KB |
Output is correct |
34 |
Correct |
118 ms |
125560 KB |
Output is correct |
35 |
Correct |
118 ms |
125584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
125560 KB |
Output is correct |
2 |
Correct |
117 ms |
125536 KB |
Output is correct |
3 |
Correct |
120 ms |
125568 KB |
Output is correct |
4 |
Correct |
126 ms |
125808 KB |
Output is correct |
5 |
Correct |
578 ms |
133000 KB |
Output is correct |
6 |
Correct |
622 ms |
132796 KB |
Output is correct |
7 |
Correct |
615 ms |
131688 KB |
Output is correct |
8 |
Correct |
118 ms |
125520 KB |
Output is correct |
9 |
Correct |
611 ms |
132240 KB |
Output is correct |
10 |
Correct |
631 ms |
132588 KB |
Output is correct |
11 |
Correct |
333 ms |
128992 KB |
Output is correct |
12 |
Correct |
634 ms |
132792 KB |
Output is correct |
13 |
Correct |
651 ms |
132660 KB |
Output is correct |
14 |
Correct |
424 ms |
131544 KB |
Output is correct |
15 |
Correct |
618 ms |
132888 KB |
Output is correct |
16 |
Correct |
475 ms |
132040 KB |
Output is correct |
17 |
Correct |
626 ms |
132824 KB |
Output is correct |
18 |
Correct |
736 ms |
132820 KB |
Output is correct |
19 |
Correct |
633 ms |
132908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
125560 KB |
Output is correct |
2 |
Correct |
119 ms |
125560 KB |
Output is correct |
3 |
Correct |
118 ms |
125688 KB |
Output is correct |
4 |
Correct |
117 ms |
125560 KB |
Output is correct |
5 |
Correct |
113 ms |
125560 KB |
Output is correct |
6 |
Correct |
115 ms |
125492 KB |
Output is correct |
7 |
Correct |
117 ms |
125544 KB |
Output is correct |
8 |
Correct |
112 ms |
125560 KB |
Output is correct |
9 |
Correct |
119 ms |
125624 KB |
Output is correct |
10 |
Correct |
119 ms |
125632 KB |
Output is correct |
11 |
Correct |
119 ms |
125560 KB |
Output is correct |
12 |
Correct |
117 ms |
125560 KB |
Output is correct |
13 |
Correct |
117 ms |
125576 KB |
Output is correct |
14 |
Correct |
120 ms |
125560 KB |
Output is correct |
15 |
Correct |
117 ms |
125612 KB |
Output is correct |
16 |
Correct |
118 ms |
125560 KB |
Output is correct |
17 |
Correct |
120 ms |
125544 KB |
Output is correct |
18 |
Correct |
116 ms |
125560 KB |
Output is correct |
19 |
Correct |
116 ms |
125596 KB |
Output is correct |
20 |
Correct |
114 ms |
125564 KB |
Output is correct |
21 |
Correct |
118 ms |
125560 KB |
Output is correct |
22 |
Correct |
119 ms |
125560 KB |
Output is correct |
23 |
Correct |
118 ms |
125556 KB |
Output is correct |
24 |
Correct |
118 ms |
125572 KB |
Output is correct |
25 |
Correct |
119 ms |
125496 KB |
Output is correct |
26 |
Correct |
119 ms |
125560 KB |
Output is correct |
27 |
Correct |
119 ms |
125560 KB |
Output is correct |
28 |
Correct |
118 ms |
125564 KB |
Output is correct |
29 |
Correct |
117 ms |
125564 KB |
Output is correct |
30 |
Correct |
118 ms |
125560 KB |
Output is correct |
31 |
Correct |
117 ms |
125588 KB |
Output is correct |
32 |
Correct |
118 ms |
125532 KB |
Output is correct |
33 |
Correct |
116 ms |
125548 KB |
Output is correct |
34 |
Correct |
118 ms |
125560 KB |
Output is correct |
35 |
Correct |
118 ms |
125584 KB |
Output is correct |
36 |
Correct |
125 ms |
125816 KB |
Output is correct |
37 |
Correct |
123 ms |
125696 KB |
Output is correct |
38 |
Correct |
125 ms |
125680 KB |
Output is correct |
39 |
Correct |
120 ms |
125764 KB |
Output is correct |
40 |
Correct |
131 ms |
125788 KB |
Output is correct |
41 |
Correct |
126 ms |
125816 KB |
Output is correct |
42 |
Correct |
135 ms |
125840 KB |
Output is correct |
43 |
Correct |
115 ms |
125524 KB |
Output is correct |
44 |
Correct |
122 ms |
125752 KB |
Output is correct |
45 |
Correct |
118 ms |
125816 KB |
Output is correct |
46 |
Correct |
124 ms |
125816 KB |
Output is correct |
47 |
Correct |
128 ms |
125944 KB |
Output is correct |
48 |
Correct |
126 ms |
125816 KB |
Output is correct |
49 |
Correct |
122 ms |
125756 KB |
Output is correct |
50 |
Correct |
124 ms |
125816 KB |
Output is correct |
51 |
Correct |
127 ms |
125788 KB |
Output is correct |
52 |
Correct |
115 ms |
125560 KB |
Output is correct |
53 |
Correct |
127 ms |
125780 KB |
Output is correct |
54 |
Correct |
120 ms |
125768 KB |
Output is correct |
55 |
Correct |
128 ms |
125812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
125560 KB |
Output is correct |
2 |
Correct |
119 ms |
125560 KB |
Output is correct |
3 |
Correct |
118 ms |
125688 KB |
Output is correct |
4 |
Correct |
117 ms |
125560 KB |
Output is correct |
5 |
Correct |
113 ms |
125560 KB |
Output is correct |
6 |
Correct |
115 ms |
125492 KB |
Output is correct |
7 |
Correct |
117 ms |
125544 KB |
Output is correct |
8 |
Correct |
112 ms |
125560 KB |
Output is correct |
9 |
Correct |
119 ms |
125624 KB |
Output is correct |
10 |
Correct |
119 ms |
125632 KB |
Output is correct |
11 |
Correct |
119 ms |
125560 KB |
Output is correct |
12 |
Correct |
117 ms |
125560 KB |
Output is correct |
13 |
Correct |
117 ms |
125576 KB |
Output is correct |
14 |
Correct |
120 ms |
125560 KB |
Output is correct |
15 |
Correct |
117 ms |
125612 KB |
Output is correct |
16 |
Correct |
118 ms |
125560 KB |
Output is correct |
17 |
Correct |
120 ms |
125544 KB |
Output is correct |
18 |
Correct |
116 ms |
125560 KB |
Output is correct |
19 |
Correct |
116 ms |
125596 KB |
Output is correct |
20 |
Correct |
114 ms |
125564 KB |
Output is correct |
21 |
Correct |
118 ms |
125560 KB |
Output is correct |
22 |
Correct |
119 ms |
125560 KB |
Output is correct |
23 |
Correct |
118 ms |
125556 KB |
Output is correct |
24 |
Correct |
118 ms |
125572 KB |
Output is correct |
25 |
Correct |
119 ms |
125496 KB |
Output is correct |
26 |
Correct |
119 ms |
125560 KB |
Output is correct |
27 |
Correct |
119 ms |
125560 KB |
Output is correct |
28 |
Correct |
118 ms |
125564 KB |
Output is correct |
29 |
Correct |
117 ms |
125564 KB |
Output is correct |
30 |
Correct |
118 ms |
125560 KB |
Output is correct |
31 |
Correct |
117 ms |
125588 KB |
Output is correct |
32 |
Correct |
118 ms |
125532 KB |
Output is correct |
33 |
Correct |
116 ms |
125548 KB |
Output is correct |
34 |
Correct |
118 ms |
125560 KB |
Output is correct |
35 |
Correct |
118 ms |
125584 KB |
Output is correct |
36 |
Correct |
113 ms |
125560 KB |
Output is correct |
37 |
Correct |
117 ms |
125536 KB |
Output is correct |
38 |
Correct |
120 ms |
125568 KB |
Output is correct |
39 |
Correct |
126 ms |
125808 KB |
Output is correct |
40 |
Correct |
578 ms |
133000 KB |
Output is correct |
41 |
Correct |
622 ms |
132796 KB |
Output is correct |
42 |
Correct |
615 ms |
131688 KB |
Output is correct |
43 |
Correct |
118 ms |
125520 KB |
Output is correct |
44 |
Correct |
611 ms |
132240 KB |
Output is correct |
45 |
Correct |
631 ms |
132588 KB |
Output is correct |
46 |
Correct |
333 ms |
128992 KB |
Output is correct |
47 |
Correct |
634 ms |
132792 KB |
Output is correct |
48 |
Correct |
651 ms |
132660 KB |
Output is correct |
49 |
Correct |
424 ms |
131544 KB |
Output is correct |
50 |
Correct |
618 ms |
132888 KB |
Output is correct |
51 |
Correct |
475 ms |
132040 KB |
Output is correct |
52 |
Correct |
626 ms |
132824 KB |
Output is correct |
53 |
Correct |
736 ms |
132820 KB |
Output is correct |
54 |
Correct |
633 ms |
132908 KB |
Output is correct |
55 |
Correct |
125 ms |
125816 KB |
Output is correct |
56 |
Correct |
123 ms |
125696 KB |
Output is correct |
57 |
Correct |
125 ms |
125680 KB |
Output is correct |
58 |
Correct |
120 ms |
125764 KB |
Output is correct |
59 |
Correct |
131 ms |
125788 KB |
Output is correct |
60 |
Correct |
126 ms |
125816 KB |
Output is correct |
61 |
Correct |
135 ms |
125840 KB |
Output is correct |
62 |
Correct |
115 ms |
125524 KB |
Output is correct |
63 |
Correct |
122 ms |
125752 KB |
Output is correct |
64 |
Correct |
118 ms |
125816 KB |
Output is correct |
65 |
Correct |
124 ms |
125816 KB |
Output is correct |
66 |
Correct |
128 ms |
125944 KB |
Output is correct |
67 |
Correct |
126 ms |
125816 KB |
Output is correct |
68 |
Correct |
122 ms |
125756 KB |
Output is correct |
69 |
Correct |
124 ms |
125816 KB |
Output is correct |
70 |
Correct |
127 ms |
125788 KB |
Output is correct |
71 |
Correct |
115 ms |
125560 KB |
Output is correct |
72 |
Correct |
127 ms |
125780 KB |
Output is correct |
73 |
Correct |
120 ms |
125768 KB |
Output is correct |
74 |
Correct |
128 ms |
125812 KB |
Output is correct |
75 |
Correct |
830 ms |
132796 KB |
Output is correct |
76 |
Correct |
571 ms |
130272 KB |
Output is correct |
77 |
Correct |
581 ms |
130616 KB |
Output is correct |
78 |
Correct |
480 ms |
129748 KB |
Output is correct |
79 |
Correct |
677 ms |
132180 KB |
Output is correct |
80 |
Correct |
825 ms |
132792 KB |
Output is correct |
81 |
Correct |
125 ms |
125720 KB |
Output is correct |
82 |
Correct |
728 ms |
132368 KB |
Output is correct |
83 |
Correct |
347 ms |
131536 KB |
Output is correct |
84 |
Correct |
697 ms |
132564 KB |
Output is correct |
85 |
Correct |
736 ms |
132856 KB |
Output is correct |
86 |
Correct |
738 ms |
132836 KB |
Output is correct |
87 |
Correct |
553 ms |
133044 KB |
Output is correct |
88 |
Correct |
541 ms |
132824 KB |
Output is correct |
89 |
Correct |
828 ms |
132812 KB |
Output is correct |
90 |
Correct |
914 ms |
132824 KB |
Output is correct |
91 |
Correct |
829 ms |
132860 KB |
Output is correct |
92 |
Correct |
758 ms |
132372 KB |
Output is correct |
93 |
Correct |
743 ms |
132924 KB |
Output is correct |
94 |
Correct |
821 ms |
133016 KB |
Output is correct |
95 |
Correct |
807 ms |
132796 KB |
Output is correct |