#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
set<pair<int, int>> nums;
void set_range(int a, int b){
auto itr = nums.lower_bound({a, 0});
int l = a, r = b;
if (itr != nums.begin()){
--itr;
int a1, b1; tie(a1, b1) = *itr;
itr++;
if (b1 >= a){
nums.erase({a1, b1});
l = a1;
}
if (b1 >= b){
r = b1;
}
}
while (itr != nums.end()){
int a1, b1; tie(a1, b1) = *itr;
if (b1 > b) break;
itr++;
nums.erase({a1, b1});
}
if (itr != nums.end()){
int a1, b1; tie(a1, b1) = *itr;
if (a1 <= b){
nums.erase(itr);
r = b1;
}
}
nums.insert({l, r});
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int l, r; cin >> l >> r;
for (int j = 0; j < r; j++){
vector<pii> ranges;
vector<int> walls;
int rptr = l;
int lptr = 0;
int x; cin >> x;
for (int i = 0; i < x; i++){
int g; cin >> g;
rptr -= g;
walls.push_back(g);
}
if (rptr == 0){
cout << l << '\n';
return 0;
}
ranges.push_back({lptr + 1, rptr});
for (int i = 0; i < x; i++){
lptr += walls[i];
rptr += walls[i];
if (ranges.back().second >= lptr){
auto [l1, r1] = ranges.back();
ranges.pop_back();
ranges.push_back({l1, rptr});
} else {
ranges.push_back({lptr + 1, rptr});
}
}
int lfree = ranges[0].second + 1;
for (int i = 1; i < ranges.size(); i++){
if (lfree <= ranges[i].first - 1) set_range(lfree, ranges[i].first - 1);
lfree = ranges[i].second + 1;
}
}
int ans = 0;
for (auto [a, b] : nums){
ans += b - a + 1;
}
cout << ans << '\n';
}
Compilation message
lasers.cpp: In function 'int main()':
lasers.cpp:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i = 1; i < ranges.size(); i++){
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
139 ms |
6252 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
7372 KB |
Output is correct |
2 |
Correct |
13 ms |
1900 KB |
Output is correct |
3 |
Correct |
14 ms |
1444 KB |
Output is correct |
4 |
Correct |
83 ms |
7828 KB |
Output is correct |
5 |
Correct |
27 ms |
2584 KB |
Output is correct |
6 |
Correct |
46 ms |
4028 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
60 ms |
6596 KB |
Output is correct |
9 |
Correct |
73 ms |
6072 KB |
Output is correct |
10 |
Correct |
115 ms |
8580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
7372 KB |
Output is correct |
2 |
Correct |
13 ms |
1900 KB |
Output is correct |
3 |
Correct |
14 ms |
1444 KB |
Output is correct |
4 |
Correct |
83 ms |
7828 KB |
Output is correct |
5 |
Correct |
27 ms |
2584 KB |
Output is correct |
6 |
Correct |
46 ms |
4028 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
60 ms |
6596 KB |
Output is correct |
9 |
Correct |
73 ms |
6072 KB |
Output is correct |
10 |
Correct |
115 ms |
8580 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
136 ms |
4716 KB |
Output is correct |
22 |
Correct |
20 ms |
1004 KB |
Output is correct |
23 |
Correct |
22 ms |
1472 KB |
Output is correct |
24 |
Correct |
91 ms |
4508 KB |
Output is correct |
25 |
Correct |
133 ms |
4616 KB |
Output is correct |
26 |
Correct |
36 ms |
1644 KB |
Output is correct |
27 |
Correct |
15 ms |
876 KB |
Output is correct |
28 |
Correct |
131 ms |
4588 KB |
Output is correct |
29 |
Correct |
130 ms |
4716 KB |
Output is correct |
30 |
Correct |
63 ms |
3564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
139 ms |
6252 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
93 ms |
7372 KB |
Output is correct |
22 |
Correct |
13 ms |
1900 KB |
Output is correct |
23 |
Correct |
14 ms |
1444 KB |
Output is correct |
24 |
Correct |
83 ms |
7828 KB |
Output is correct |
25 |
Correct |
27 ms |
2584 KB |
Output is correct |
26 |
Correct |
46 ms |
4028 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
60 ms |
6596 KB |
Output is correct |
29 |
Correct |
73 ms |
6072 KB |
Output is correct |
30 |
Correct |
115 ms |
8580 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
1 ms |
384 KB |
Output is correct |
41 |
Correct |
136 ms |
4716 KB |
Output is correct |
42 |
Correct |
20 ms |
1004 KB |
Output is correct |
43 |
Correct |
22 ms |
1472 KB |
Output is correct |
44 |
Correct |
91 ms |
4508 KB |
Output is correct |
45 |
Correct |
133 ms |
4616 KB |
Output is correct |
46 |
Correct |
36 ms |
1644 KB |
Output is correct |
47 |
Correct |
15 ms |
876 KB |
Output is correct |
48 |
Correct |
131 ms |
4588 KB |
Output is correct |
49 |
Correct |
130 ms |
4716 KB |
Output is correct |
50 |
Correct |
63 ms |
3564 KB |
Output is correct |
51 |
Correct |
28 ms |
1944 KB |
Output is correct |
52 |
Correct |
142 ms |
6124 KB |
Output is correct |
53 |
Correct |
141 ms |
5868 KB |
Output is correct |
54 |
Correct |
38 ms |
1828 KB |
Output is correct |
55 |
Correct |
66 ms |
3692 KB |
Output is correct |
56 |
Correct |
88 ms |
5464 KB |
Output is correct |
57 |
Correct |
43 ms |
2412 KB |
Output is correct |
58 |
Correct |
141 ms |
5996 KB |
Output is correct |
59 |
Correct |
32 ms |
1900 KB |
Output is correct |
60 |
Correct |
46 ms |
2688 KB |
Output is correct |