# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
20563 |
2017-02-12T10:41:14 Z |
CodingAmolang(#71, sys7961) |
초음속철도 (OJUZ11_rail) |
C++11 |
|
726 ms |
34896 KB |
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using std::queue;
using std::vector;
const long long MOD = 1000000007;
long long poww(long long a, long long b) {
if (b == 0)return 1;
long long tmp = poww(a, b / 2);
if (b % 2 == 1)return (((tmp*tmp) % MOD)*a) % MOD;
return (tmp*tmp) % MOD;
}
struct segment_tree {
vector<long long> tree;
vector<long long> lazy;
int k = 1;
int n;
segment_tree(int n) :n(n) {
while (k <= n)k *= 2;
tree.resize(k * 3);
lazy.resize(k * 3,1);
}
void update_lazy(int node, int start, int end) {
if (lazy[node] != 1) {
tree[node] *= lazy[node];
tree[node] %= MOD;
if (start != end) {
lazy[node * 2] *= lazy[node];
lazy[node * 2 + 1] *= lazy[node];
lazy[node * 2] %= MOD;
lazy[node * 2 + 1] %= MOD;
}
lazy[node] = 1;
}
}
void update_range(int node, int start, int end, int left, int right, long long diff) {
update_lazy(node, start, end);
if (left > end || right < start) {
return;
}
if (left <= start && end <= right) {
tree[node] *= diff;
tree[node] %= MOD;
if (start != end) {
lazy[node * 2] *= diff;
lazy[node * 2 + 1]*=diff;
lazy[node * 2] %= MOD;
lazy[node * 2 + 1] %= MOD;
}
return;
}
update_range(node * 2, start, (start + end) / 2, left, right, diff);
update_range(node * 2 + 1, (start + end) / 2 + 1, end, left, right, diff);
tree[node] = (tree[node * 2] + tree[node * 2 + 1]) % MOD;
}
void update_one(int node, int start, int end, int left, int right, long long diff) {
update_lazy(node, start, end);
if (left > end || right < start) {
return;
}
if (left <= start && end <= right) {
tree[node] += diff;
tree[node] %= MOD;
return;
}
update_one(node * 2, start, (start + end) / 2, left, right, diff);
update_one(node * 2 + 1, (start + end) / 2 + 1, end, left, right, diff);
tree[node] = (tree[node * 2] + tree[node * 2 + 1]) % MOD;
}
long long sum(int node, int start, int end, int left, int right) {
update_lazy(node, start, end);
if (left > end || right < start) {
return 0;
}
if (left <= start && end <= right) {
return tree[node];
}
return sum(node * 2, start, (start + end) / 2, left, right) + sum(node * 2 + 1, (start + end) / 2 + 1, end, left, right);
}
long long getSum(int left, int right) {
return sum(1, 0, n - 1, left, right);
}
void update(int left, int right, long long diff) {
update_range(1, 0, n - 1, left, right, diff);
}
void update_plus(int idx, long long a) {
update_range(1, 0, n - 1, idx, idx, 1);
update_one(1, 0, n - 1, idx, idx, a);
}
};
using std::pair;
int main() {
int n, m;
scanf("%d%d", &n, &m);
vector<long long> X = { 1,n };
vector<pair<long long, long long>> seg;
for (int i = 0; i < m; i++) {
long long s, e;
scanf("%lld%lld", &s, &e);
seg.push_back({ s,e });
X.push_back(s);
X.push_back(e);
}
std::sort(seg.begin(), seg.end());
std::sort(X.begin(), X.end());
X.erase(std::unique(X.begin(), X.end()), X.end());
segment_tree tree(X.size());
tree.update_plus(0, 1);
for (auto segment : seg) {
long long s = std::lower_bound(X.begin(), X.end(), segment.first) - X.begin();
long long e = std::lower_bound(X.begin(), X.end(), segment.second) - X.begin();
tree.update_plus(e, tree.getSum(s, e));
tree.update(e + 1, X.size() - 1, 2);
}
printf("%lld", tree.getSum(X.size() - 1, X.size() - 1));
}
Compilation message
rail.cpp: In function 'int main()':
rail.cpp:97: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:102:28: 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 |
0 ms |
1952 KB |
Output is correct |
2 |
Correct |
0 ms |
1952 KB |
Output is correct |
3 |
Correct |
0 ms |
1952 KB |
Output is correct |
4 |
Correct |
0 ms |
1952 KB |
Output is correct |
5 |
Correct |
0 ms |
1952 KB |
Output is correct |
6 |
Correct |
0 ms |
1952 KB |
Output is correct |
7 |
Correct |
0 ms |
1952 KB |
Output is correct |
8 |
Correct |
0 ms |
1952 KB |
Output is correct |
9 |
Correct |
0 ms |
1952 KB |
Output is correct |
10 |
Correct |
0 ms |
1952 KB |
Output is correct |
11 |
Correct |
0 ms |
1952 KB |
Output is correct |
12 |
Correct |
0 ms |
1952 KB |
Output is correct |
13 |
Correct |
0 ms |
1952 KB |
Output is correct |
14 |
Correct |
0 ms |
1952 KB |
Output is correct |
15 |
Correct |
0 ms |
1952 KB |
Output is correct |
16 |
Correct |
0 ms |
1952 KB |
Output is correct |
17 |
Correct |
0 ms |
1952 KB |
Output is correct |
18 |
Correct |
0 ms |
1952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1952 KB |
Output is correct |
2 |
Correct |
0 ms |
1952 KB |
Output is correct |
3 |
Correct |
0 ms |
1952 KB |
Output is correct |
4 |
Correct |
0 ms |
1952 KB |
Output is correct |
5 |
Correct |
0 ms |
1952 KB |
Output is correct |
6 |
Correct |
0 ms |
1952 KB |
Output is correct |
7 |
Correct |
0 ms |
1952 KB |
Output is correct |
8 |
Correct |
0 ms |
1952 KB |
Output is correct |
9 |
Correct |
0 ms |
1952 KB |
Output is correct |
10 |
Correct |
0 ms |
1952 KB |
Output is correct |
11 |
Correct |
0 ms |
1952 KB |
Output is correct |
12 |
Correct |
0 ms |
1952 KB |
Output is correct |
13 |
Correct |
0 ms |
1952 KB |
Output is correct |
14 |
Correct |
0 ms |
1952 KB |
Output is correct |
15 |
Correct |
0 ms |
1952 KB |
Output is correct |
16 |
Correct |
0 ms |
1952 KB |
Output is correct |
17 |
Correct |
0 ms |
1952 KB |
Output is correct |
18 |
Correct |
0 ms |
1952 KB |
Output is correct |
19 |
Correct |
0 ms |
1952 KB |
Output is correct |
20 |
Correct |
0 ms |
1952 KB |
Output is correct |
21 |
Correct |
0 ms |
1952 KB |
Output is correct |
22 |
Correct |
0 ms |
1952 KB |
Output is correct |
23 |
Correct |
0 ms |
1952 KB |
Output is correct |
24 |
Correct |
0 ms |
1952 KB |
Output is correct |
25 |
Correct |
0 ms |
1952 KB |
Output is correct |
26 |
Correct |
0 ms |
1952 KB |
Output is correct |
27 |
Correct |
0 ms |
1952 KB |
Output is correct |
28 |
Correct |
0 ms |
1952 KB |
Output is correct |
29 |
Correct |
0 ms |
1952 KB |
Output is correct |
30 |
Correct |
0 ms |
1952 KB |
Output is correct |
31 |
Correct |
0 ms |
1952 KB |
Output is correct |
32 |
Correct |
0 ms |
1952 KB |
Output is correct |
33 |
Correct |
0 ms |
1952 KB |
Output is correct |
34 |
Correct |
0 ms |
1952 KB |
Output is correct |
35 |
Correct |
0 ms |
1952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1952 KB |
Output is correct |
2 |
Correct |
0 ms |
1952 KB |
Output is correct |
3 |
Correct |
0 ms |
1952 KB |
Output is correct |
4 |
Correct |
3 ms |
2384 KB |
Output is correct |
5 |
Correct |
259 ms |
13300 KB |
Output is correct |
6 |
Correct |
406 ms |
34896 KB |
Output is correct |
7 |
Correct |
379 ms |
34896 KB |
Output is correct |
8 |
Correct |
0 ms |
1952 KB |
Output is correct |
9 |
Correct |
379 ms |
34896 KB |
Output is correct |
10 |
Correct |
383 ms |
34896 KB |
Output is correct |
11 |
Correct |
163 ms |
9296 KB |
Output is correct |
12 |
Correct |
409 ms |
34896 KB |
Output is correct |
13 |
Correct |
406 ms |
34896 KB |
Output is correct |
14 |
Correct |
86 ms |
12364 KB |
Output is correct |
15 |
Correct |
386 ms |
22608 KB |
Output is correct |
16 |
Correct |
79 ms |
12364 KB |
Output is correct |
17 |
Correct |
413 ms |
34896 KB |
Output is correct |
18 |
Correct |
399 ms |
34896 KB |
Output is correct |
19 |
Correct |
396 ms |
34896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1952 KB |
Output is correct |
2 |
Correct |
0 ms |
1952 KB |
Output is correct |
3 |
Correct |
0 ms |
1952 KB |
Output is correct |
4 |
Correct |
0 ms |
1952 KB |
Output is correct |
5 |
Correct |
0 ms |
1952 KB |
Output is correct |
6 |
Correct |
0 ms |
1952 KB |
Output is correct |
7 |
Correct |
0 ms |
1952 KB |
Output is correct |
8 |
Correct |
0 ms |
1952 KB |
Output is correct |
9 |
Correct |
0 ms |
1952 KB |
Output is correct |
10 |
Correct |
0 ms |
1952 KB |
Output is correct |
11 |
Correct |
0 ms |
1952 KB |
Output is correct |
12 |
Correct |
0 ms |
1952 KB |
Output is correct |
13 |
Correct |
0 ms |
1952 KB |
Output is correct |
14 |
Correct |
0 ms |
1952 KB |
Output is correct |
15 |
Correct |
0 ms |
1952 KB |
Output is correct |
16 |
Correct |
0 ms |
1952 KB |
Output is correct |
17 |
Correct |
0 ms |
1952 KB |
Output is correct |
18 |
Correct |
0 ms |
1952 KB |
Output is correct |
19 |
Correct |
0 ms |
1952 KB |
Output is correct |
20 |
Correct |
0 ms |
1952 KB |
Output is correct |
21 |
Correct |
0 ms |
1952 KB |
Output is correct |
22 |
Correct |
0 ms |
1952 KB |
Output is correct |
23 |
Correct |
0 ms |
1952 KB |
Output is correct |
24 |
Correct |
0 ms |
1952 KB |
Output is correct |
25 |
Correct |
0 ms |
1952 KB |
Output is correct |
26 |
Correct |
0 ms |
1952 KB |
Output is correct |
27 |
Correct |
0 ms |
1952 KB |
Output is correct |
28 |
Correct |
0 ms |
1952 KB |
Output is correct |
29 |
Correct |
0 ms |
1952 KB |
Output is correct |
30 |
Correct |
0 ms |
1952 KB |
Output is correct |
31 |
Correct |
0 ms |
1952 KB |
Output is correct |
32 |
Correct |
0 ms |
1952 KB |
Output is correct |
33 |
Correct |
0 ms |
1952 KB |
Output is correct |
34 |
Correct |
0 ms |
1952 KB |
Output is correct |
35 |
Correct |
0 ms |
1952 KB |
Output is correct |
36 |
Correct |
6 ms |
3020 KB |
Output is correct |
37 |
Correct |
6 ms |
2636 KB |
Output is correct |
38 |
Correct |
6 ms |
2468 KB |
Output is correct |
39 |
Correct |
0 ms |
2244 KB |
Output is correct |
40 |
Correct |
6 ms |
2636 KB |
Output is correct |
41 |
Correct |
9 ms |
3020 KB |
Output is correct |
42 |
Correct |
6 ms |
3020 KB |
Output is correct |
43 |
Correct |
0 ms |
1952 KB |
Output is correct |
44 |
Correct |
6 ms |
2636 KB |
Output is correct |
45 |
Correct |
0 ms |
2244 KB |
Output is correct |
46 |
Correct |
3 ms |
2636 KB |
Output is correct |
47 |
Correct |
6 ms |
2636 KB |
Output is correct |
48 |
Correct |
6 ms |
2636 KB |
Output is correct |
49 |
Correct |
3 ms |
2244 KB |
Output is correct |
50 |
Correct |
3 ms |
2244 KB |
Output is correct |
51 |
Correct |
3 ms |
2244 KB |
Output is correct |
52 |
Correct |
0 ms |
2128 KB |
Output is correct |
53 |
Correct |
6 ms |
3020 KB |
Output is correct |
54 |
Correct |
3 ms |
2336 KB |
Output is correct |
55 |
Correct |
9 ms |
3020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1952 KB |
Output is correct |
2 |
Correct |
0 ms |
1952 KB |
Output is correct |
3 |
Correct |
0 ms |
1952 KB |
Output is correct |
4 |
Correct |
0 ms |
1952 KB |
Output is correct |
5 |
Correct |
0 ms |
1952 KB |
Output is correct |
6 |
Correct |
0 ms |
1952 KB |
Output is correct |
7 |
Correct |
0 ms |
1952 KB |
Output is correct |
8 |
Correct |
0 ms |
1952 KB |
Output is correct |
9 |
Correct |
0 ms |
1952 KB |
Output is correct |
10 |
Correct |
0 ms |
1952 KB |
Output is correct |
11 |
Correct |
0 ms |
1952 KB |
Output is correct |
12 |
Correct |
0 ms |
1952 KB |
Output is correct |
13 |
Correct |
0 ms |
1952 KB |
Output is correct |
14 |
Correct |
0 ms |
1952 KB |
Output is correct |
15 |
Correct |
0 ms |
1952 KB |
Output is correct |
16 |
Correct |
0 ms |
1952 KB |
Output is correct |
17 |
Correct |
0 ms |
1952 KB |
Output is correct |
18 |
Correct |
0 ms |
1952 KB |
Output is correct |
19 |
Correct |
0 ms |
1952 KB |
Output is correct |
20 |
Correct |
0 ms |
1952 KB |
Output is correct |
21 |
Correct |
0 ms |
1952 KB |
Output is correct |
22 |
Correct |
0 ms |
1952 KB |
Output is correct |
23 |
Correct |
0 ms |
1952 KB |
Output is correct |
24 |
Correct |
0 ms |
1952 KB |
Output is correct |
25 |
Correct |
0 ms |
1952 KB |
Output is correct |
26 |
Correct |
0 ms |
1952 KB |
Output is correct |
27 |
Correct |
0 ms |
1952 KB |
Output is correct |
28 |
Correct |
0 ms |
1952 KB |
Output is correct |
29 |
Correct |
0 ms |
1952 KB |
Output is correct |
30 |
Correct |
0 ms |
1952 KB |
Output is correct |
31 |
Correct |
0 ms |
1952 KB |
Output is correct |
32 |
Correct |
0 ms |
1952 KB |
Output is correct |
33 |
Correct |
0 ms |
1952 KB |
Output is correct |
34 |
Correct |
0 ms |
1952 KB |
Output is correct |
35 |
Correct |
0 ms |
1952 KB |
Output is correct |
36 |
Correct |
0 ms |
1952 KB |
Output is correct |
37 |
Correct |
0 ms |
1952 KB |
Output is correct |
38 |
Correct |
0 ms |
1952 KB |
Output is correct |
39 |
Correct |
3 ms |
2384 KB |
Output is correct |
40 |
Correct |
259 ms |
13300 KB |
Output is correct |
41 |
Correct |
406 ms |
34896 KB |
Output is correct |
42 |
Correct |
379 ms |
34896 KB |
Output is correct |
43 |
Correct |
0 ms |
1952 KB |
Output is correct |
44 |
Correct |
379 ms |
34896 KB |
Output is correct |
45 |
Correct |
383 ms |
34896 KB |
Output is correct |
46 |
Correct |
163 ms |
9296 KB |
Output is correct |
47 |
Correct |
409 ms |
34896 KB |
Output is correct |
48 |
Correct |
406 ms |
34896 KB |
Output is correct |
49 |
Correct |
86 ms |
12364 KB |
Output is correct |
50 |
Correct |
386 ms |
22608 KB |
Output is correct |
51 |
Correct |
79 ms |
12364 KB |
Output is correct |
52 |
Correct |
413 ms |
34896 KB |
Output is correct |
53 |
Correct |
399 ms |
34896 KB |
Output is correct |
54 |
Correct |
396 ms |
34896 KB |
Output is correct |
55 |
Correct |
6 ms |
3020 KB |
Output is correct |
56 |
Correct |
6 ms |
2636 KB |
Output is correct |
57 |
Correct |
6 ms |
2468 KB |
Output is correct |
58 |
Correct |
0 ms |
2244 KB |
Output is correct |
59 |
Correct |
6 ms |
2636 KB |
Output is correct |
60 |
Correct |
9 ms |
3020 KB |
Output is correct |
61 |
Correct |
6 ms |
3020 KB |
Output is correct |
62 |
Correct |
0 ms |
1952 KB |
Output is correct |
63 |
Correct |
6 ms |
2636 KB |
Output is correct |
64 |
Correct |
0 ms |
2244 KB |
Output is correct |
65 |
Correct |
3 ms |
2636 KB |
Output is correct |
66 |
Correct |
6 ms |
2636 KB |
Output is correct |
67 |
Correct |
6 ms |
2636 KB |
Output is correct |
68 |
Correct |
3 ms |
2244 KB |
Output is correct |
69 |
Correct |
3 ms |
2244 KB |
Output is correct |
70 |
Correct |
3 ms |
2244 KB |
Output is correct |
71 |
Correct |
0 ms |
2128 KB |
Output is correct |
72 |
Correct |
6 ms |
3020 KB |
Output is correct |
73 |
Correct |
3 ms |
2336 KB |
Output is correct |
74 |
Correct |
9 ms |
3020 KB |
Output is correct |
75 |
Correct |
703 ms |
34896 KB |
Output is correct |
76 |
Correct |
436 ms |
20560 KB |
Output is correct |
77 |
Correct |
303 ms |
12364 KB |
Output is correct |
78 |
Correct |
79 ms |
12364 KB |
Output is correct |
79 |
Correct |
493 ms |
16464 KB |
Output is correct |
80 |
Correct |
659 ms |
34896 KB |
Output is correct |
81 |
Correct |
6 ms |
2636 KB |
Output is correct |
82 |
Correct |
649 ms |
34896 KB |
Output is correct |
83 |
Correct |
59 ms |
12364 KB |
Output is correct |
84 |
Correct |
523 ms |
34896 KB |
Output is correct |
85 |
Correct |
536 ms |
22608 KB |
Output is correct |
86 |
Correct |
563 ms |
22608 KB |
Output is correct |
87 |
Correct |
159 ms |
12364 KB |
Output is correct |
88 |
Correct |
163 ms |
12364 KB |
Output is correct |
89 |
Correct |
703 ms |
34896 KB |
Output is correct |
90 |
Correct |
706 ms |
34896 KB |
Output is correct |
91 |
Correct |
699 ms |
34896 KB |
Output is correct |
92 |
Correct |
629 ms |
34896 KB |
Output is correct |
93 |
Correct |
549 ms |
22608 KB |
Output is correct |
94 |
Correct |
716 ms |
34896 KB |
Output is correct |
95 |
Correct |
726 ms |
34896 KB |
Output is correct |