#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, q;
cin >> n >> q;
vector<pair<int, int>> xy(n);
bool check = true;
for (int i = 0; i < n; ++i) {
cin >> xy[i].first >> xy[i].second;
if (xy[i].first != xy[i].second) {
check = false;
}
}
vector<int> t(q);
for (int i = 0; i < q; ++i) {
cin >> t[i];
}
if (!check) {
vector<int> ans(t[q - 1] + 1);
ans[0] = xy.size();
set<pair<int, int>> black, gray;
for (int i = 0; i < n; ++i) {
black.insert(xy[i]);
}
for (int i = 1; i <= t[q - 1]; ++i) {
set<pair<int, int>> black_nw;
for (auto [x, y] : black) {
if (!black.count({x + 1, y}) && !gray.count({x + 1, y})) {
black_nw.emplace(x + 1, y);
}
if (!black.count({x - 1, y}) && !gray.count({x - 1, y})) {
black_nw.emplace(x - 1, y);
}
if (!black.count({x, y + 1}) && !gray.count({x, y + 1})) {
black_nw.emplace(x, y + 1);
}
if (!black.count({x, y - 1}) && !gray.count({x, y - 1})) {
black_nw.emplace(x, y - 1);
}
}
gray = black;
black = black_nw;
ans[i] = black.size();
}
for (int i = 0; i < q; ++i) {
cout << ans[t[i]] << '\n';
}
} else {
sort(xy.begin(), xy.end());
vector<pair<int, int>> tms;
for (int i = 0; i < q; ++i) {
tms.emplace_back(t[i], n);
}
for (int i = 0; i + 1 < n; ++i) {
tms.emplace_back(xy[i + 1].first - xy[i].first, i);
tms.emplace_back(xy[i + 1].first - xy[i].first + 1, i);
}
sort(tms.begin(), tms.end());
map<int, long long> ans;
set<pair<int, int>> segms;
for (int i = 0; i < n; ++i) {
segms.emplace(i, i + 1);
}
int cntp = 0;
for (auto [t, ind] : tms) {
if (ind < n) {
if (t == xy[ind + 1].first - xy[ind].first) {
auto it = segms.lower_bound(make_pair(ind + 1, -1));
int r = it->second;
it--;
int l = it->first;
segms.erase(segms.lower_bound(make_pair(l, -1)));
segms.erase(segms.lower_bound(make_pair(ind + 1, -1)));
segms.emplace(l, r);
cntp++;
} else {
cntp--;
}
} else {
if (t == 0) {
ans[t] = n;
} else {
for (auto [l, r] : segms) {
ans[t] += (xy[r - 1].first - xy[l].first + 1 + t) * 1LL * 2 + (t - 1) * 1LL * 2;
}
ans[t] += cntp * 1LL * (t - 1);
}
}
}
for (int i = 0; i < q; ++i) {
cout << ans[t[i]] << '\n';
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
348 KB |
Output is correct |
4 |
Correct |
17 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
15 ms |
1368 KB |
Output is correct |
9 |
Correct |
16 ms |
344 KB |
Output is correct |
10 |
Correct |
15 ms |
348 KB |
Output is correct |
11 |
Correct |
15 ms |
588 KB |
Output is correct |
12 |
Correct |
18 ms |
1112 KB |
Output is correct |
13 |
Correct |
18 ms |
856 KB |
Output is correct |
14 |
Correct |
19 ms |
856 KB |
Output is correct |
15 |
Correct |
18 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
452 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
476 KB |
Output is correct |
20 |
Correct |
3 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
460 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
348 KB |
Output is correct |
4 |
Correct |
17 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
15 ms |
1368 KB |
Output is correct |
9 |
Correct |
16 ms |
344 KB |
Output is correct |
10 |
Correct |
15 ms |
348 KB |
Output is correct |
11 |
Correct |
15 ms |
588 KB |
Output is correct |
12 |
Correct |
18 ms |
1112 KB |
Output is correct |
13 |
Correct |
18 ms |
856 KB |
Output is correct |
14 |
Correct |
19 ms |
856 KB |
Output is correct |
15 |
Correct |
18 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
452 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
476 KB |
Output is correct |
20 |
Correct |
3 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
460 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
3 ms |
348 KB |
Output is correct |
29 |
Correct |
999 ms |
988 KB |
Output is correct |
30 |
Correct |
1641 ms |
1088 KB |
Output is correct |
31 |
Correct |
2575 ms |
1856 KB |
Output is correct |
32 |
Correct |
4525 ms |
42892 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
235 ms |
704 KB |
Output is correct |
37 |
Correct |
236 ms |
596 KB |
Output is correct |
38 |
Correct |
3947 ms |
5812 KB |
Output is correct |
39 |
Correct |
4318 ms |
17424 KB |
Output is correct |
40 |
Correct |
4230 ms |
49028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
9280 KB |
Output is correct |
2 |
Correct |
108 ms |
9416 KB |
Output is correct |
3 |
Correct |
108 ms |
9420 KB |
Output is correct |
4 |
Correct |
108 ms |
9420 KB |
Output is correct |
5 |
Correct |
119 ms |
9316 KB |
Output is correct |
6 |
Correct |
111 ms |
9416 KB |
Output is correct |
7 |
Correct |
111 ms |
9544 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Incorrect |
111 ms |
9544 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
9280 KB |
Output is correct |
2 |
Correct |
108 ms |
9416 KB |
Output is correct |
3 |
Correct |
108 ms |
9420 KB |
Output is correct |
4 |
Correct |
108 ms |
9420 KB |
Output is correct |
5 |
Correct |
119 ms |
9316 KB |
Output is correct |
6 |
Correct |
111 ms |
9416 KB |
Output is correct |
7 |
Correct |
111 ms |
9544 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Incorrect |
111 ms |
9544 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4041 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4041 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
348 KB |
Output is correct |
4 |
Correct |
17 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
15 ms |
1368 KB |
Output is correct |
9 |
Correct |
16 ms |
344 KB |
Output is correct |
10 |
Correct |
15 ms |
348 KB |
Output is correct |
11 |
Correct |
15 ms |
588 KB |
Output is correct |
12 |
Correct |
18 ms |
1112 KB |
Output is correct |
13 |
Correct |
18 ms |
856 KB |
Output is correct |
14 |
Correct |
19 ms |
856 KB |
Output is correct |
15 |
Correct |
18 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
452 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
476 KB |
Output is correct |
20 |
Correct |
3 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
460 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
3 ms |
348 KB |
Output is correct |
29 |
Correct |
999 ms |
988 KB |
Output is correct |
30 |
Correct |
1641 ms |
1088 KB |
Output is correct |
31 |
Correct |
2575 ms |
1856 KB |
Output is correct |
32 |
Correct |
4525 ms |
42892 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
235 ms |
704 KB |
Output is correct |
37 |
Correct |
236 ms |
596 KB |
Output is correct |
38 |
Correct |
3947 ms |
5812 KB |
Output is correct |
39 |
Correct |
4318 ms |
17424 KB |
Output is correct |
40 |
Correct |
4230 ms |
49028 KB |
Output is correct |
41 |
Correct |
109 ms |
9280 KB |
Output is correct |
42 |
Correct |
108 ms |
9416 KB |
Output is correct |
43 |
Correct |
108 ms |
9420 KB |
Output is correct |
44 |
Correct |
108 ms |
9420 KB |
Output is correct |
45 |
Correct |
119 ms |
9316 KB |
Output is correct |
46 |
Correct |
111 ms |
9416 KB |
Output is correct |
47 |
Correct |
111 ms |
9544 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
50 |
Correct |
1 ms |
344 KB |
Output is correct |
51 |
Incorrect |
111 ms |
9544 KB |
Output isn't correct |
52 |
Halted |
0 ms |
0 KB |
- |