#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (auto i = (l); i < (r); i++)
#define ForE(i, l, r) for (auto i = (l); i <= (r); i++)
#define FordE(i, l, r) for (auto i = (l); i >= (r); i--)
#define Fora(v, a) for (auto v: (a))
#define bend(a) (a).begin(), (a).end()
#define isz(a) ((signed)(a).size())
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using vi = vector <int>;
using vpii = vector <pii>;
using vvi = vector <vi>;
const int N = 1e5 + 5, Q = 5e5 + 5;
struct point{
int x, y;
};
int n, q;
point a[N];
int b[Q];
namespace subtask12{
bool check(){
ForE(i, 1, n){
if (not (abs(a[i].x) <= 1000 and abs(a[i].y) <= 1000)){
return false;
}
}
ForE(i, 1, q){
if (not (b[i] <= 1000)){
return false;
}
}
return true;
}
const int N = 4e3 + 5, offset = 2e3;
int dist[N][N];
int ans[N];
vpii dir = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
void solve(){
For(x, 0, N){
For(y, 0, N){
dist[x][y] = -1;
}
}
queue <pii> qu;
ForE(i, 1, n){
a[i].x += offset; a[i].y += offset;
dist[a[i].x][a[i].y] = 0;
qu.emplace(a[i].x, a[i].y);
}
while (not qu.empty()){
auto [x, y] = qu.front(); qu.pop();
ans[dist[x][y]]++;
if (dist[x][y] == N - 1){
break;
}
for (auto [dx, dy]: dir){
int tx = x + dx, ty = y + dy;
if (0 <= tx and tx < N and 0 <= ty and ty < N and dist[tx][ty] == -1){
dist[tx][ty] = dist[x][y] + 1;
qu.emplace(tx, ty);
}
}
}
ForE(i, 1, q){
cout << ans[b[i]] << "\n";
}
}
}
namespace subtask34{
bool check(){
ForE(i, 1, n){
if (not (a[i].x == a[i].y)){
return false;
}
}
return true;
}
vector <int> dif;
vector <ll> suffdif;
ll count_dist(int t){
if (t < 0){
return 0ll;
}
int idx = upper_bound(bend(dif), t) - dif.begin();
int cnt = isz(dif) - idx;
ll area = (2ll * a[n].x + t) - (2ll * a[1].x - t) + 1;
area -= (idx != isz(dif) ? suffdif[idx] : 0ll) * 2;
area += (2 * t + 1) * cnt;
area *= (2 * t + 1);
return (area - (cnt + 1)) / 2 + (cnt + 1);
}
void solve(){
sort(a + 1, a + n + 1, [&](const point& p, const point& q){
return p.x < q.x;
});
ForE(i, 2, n){
dif.emplace_back(a[i].x - a[i - 1].x);
}
sort(bend(dif));
suffdif = vector <ll>(bend(dif));
FordE(i, isz(suffdif) - 2, 0){
suffdif[i] += suffdif[i + 1];
}
ForE(i, 1, q){
ll ans = count_dist(b[i]) - count_dist(b[i] - 1);
cout << ans << "\n";
}
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("KEK.inp", "r", stdin);
// freopen("KEK.out", "w", stdout);
cin >> n >> q;
ForE(i, 1, n){
cin >> a[i].x >> a[i].y;
}
ForE(i, 1, q){
cin >> b[i];
}
if (subtask12::check()){
subtask12::solve();
return 0;
}
if (subtask34::check()){
subtask34::solve();
return 0;
}
}
/*
==================================================+
INPUT |
--------------------------------------------------|
--------------------------------------------------|
==================================================+
OUTPUT |
--------------------------------------------------|
--------------------------------------------------|
==================================================+
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
416 ms |
63172 KB |
Output is correct |
2 |
Correct |
398 ms |
63172 KB |
Output is correct |
3 |
Correct |
408 ms |
63172 KB |
Output is correct |
4 |
Correct |
405 ms |
63060 KB |
Output is correct |
5 |
Correct |
462 ms |
63244 KB |
Output is correct |
6 |
Correct |
409 ms |
63264 KB |
Output is correct |
7 |
Correct |
410 ms |
63216 KB |
Output is correct |
8 |
Correct |
439 ms |
63260 KB |
Output is correct |
9 |
Correct |
420 ms |
63168 KB |
Output is correct |
10 |
Correct |
409 ms |
63176 KB |
Output is correct |
11 |
Correct |
427 ms |
63164 KB |
Output is correct |
12 |
Correct |
385 ms |
63180 KB |
Output is correct |
13 |
Correct |
440 ms |
63188 KB |
Output is correct |
14 |
Correct |
411 ms |
63184 KB |
Output is correct |
15 |
Correct |
400 ms |
63192 KB |
Output is correct |
16 |
Correct |
466 ms |
63168 KB |
Output is correct |
17 |
Correct |
426 ms |
63168 KB |
Output is correct |
18 |
Correct |
485 ms |
63100 KB |
Output is correct |
19 |
Correct |
412 ms |
63164 KB |
Output is correct |
20 |
Correct |
585 ms |
63244 KB |
Output is correct |
21 |
Correct |
411 ms |
63168 KB |
Output is correct |
22 |
Correct |
444 ms |
63148 KB |
Output is correct |
23 |
Correct |
432 ms |
63172 KB |
Output is correct |
24 |
Correct |
426 ms |
63248 KB |
Output is correct |
25 |
Correct |
400 ms |
63168 KB |
Output is correct |
26 |
Correct |
424 ms |
63172 KB |
Output is correct |
27 |
Correct |
568 ms |
63176 KB |
Output is correct |
28 |
Correct |
415 ms |
63232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
416 ms |
63172 KB |
Output is correct |
2 |
Correct |
398 ms |
63172 KB |
Output is correct |
3 |
Correct |
408 ms |
63172 KB |
Output is correct |
4 |
Correct |
405 ms |
63060 KB |
Output is correct |
5 |
Correct |
462 ms |
63244 KB |
Output is correct |
6 |
Correct |
409 ms |
63264 KB |
Output is correct |
7 |
Correct |
410 ms |
63216 KB |
Output is correct |
8 |
Correct |
439 ms |
63260 KB |
Output is correct |
9 |
Correct |
420 ms |
63168 KB |
Output is correct |
10 |
Correct |
409 ms |
63176 KB |
Output is correct |
11 |
Correct |
427 ms |
63164 KB |
Output is correct |
12 |
Correct |
385 ms |
63180 KB |
Output is correct |
13 |
Correct |
440 ms |
63188 KB |
Output is correct |
14 |
Correct |
411 ms |
63184 KB |
Output is correct |
15 |
Correct |
400 ms |
63192 KB |
Output is correct |
16 |
Correct |
466 ms |
63168 KB |
Output is correct |
17 |
Correct |
426 ms |
63168 KB |
Output is correct |
18 |
Correct |
485 ms |
63100 KB |
Output is correct |
19 |
Correct |
412 ms |
63164 KB |
Output is correct |
20 |
Correct |
585 ms |
63244 KB |
Output is correct |
21 |
Correct |
411 ms |
63168 KB |
Output is correct |
22 |
Correct |
444 ms |
63148 KB |
Output is correct |
23 |
Correct |
432 ms |
63172 KB |
Output is correct |
24 |
Correct |
426 ms |
63248 KB |
Output is correct |
25 |
Correct |
400 ms |
63168 KB |
Output is correct |
26 |
Correct |
424 ms |
63172 KB |
Output is correct |
27 |
Correct |
568 ms |
63176 KB |
Output is correct |
28 |
Correct |
415 ms |
63232 KB |
Output is correct |
29 |
Correct |
424 ms |
63272 KB |
Output is correct |
30 |
Correct |
395 ms |
63176 KB |
Output is correct |
31 |
Correct |
401 ms |
63176 KB |
Output is correct |
32 |
Correct |
417 ms |
66404 KB |
Output is correct |
33 |
Correct |
434 ms |
63192 KB |
Output is correct |
34 |
Correct |
431 ms |
63172 KB |
Output is correct |
35 |
Correct |
415 ms |
63316 KB |
Output is correct |
36 |
Correct |
389 ms |
63172 KB |
Output is correct |
37 |
Correct |
401 ms |
63140 KB |
Output is correct |
38 |
Correct |
389 ms |
63428 KB |
Output is correct |
39 |
Correct |
417 ms |
64192 KB |
Output is correct |
40 |
Correct |
454 ms |
66996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
2388 KB |
Output is correct |
2 |
Correct |
30 ms |
2396 KB |
Output is correct |
3 |
Correct |
29 ms |
2320 KB |
Output is correct |
4 |
Correct |
29 ms |
2360 KB |
Output is correct |
5 |
Correct |
29 ms |
2416 KB |
Output is correct |
6 |
Correct |
29 ms |
2348 KB |
Output is correct |
7 |
Correct |
29 ms |
2404 KB |
Output is correct |
8 |
Correct |
404 ms |
63292 KB |
Output is correct |
9 |
Correct |
401 ms |
63136 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
29 ms |
2388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
2388 KB |
Output is correct |
2 |
Correct |
30 ms |
2396 KB |
Output is correct |
3 |
Correct |
29 ms |
2320 KB |
Output is correct |
4 |
Correct |
29 ms |
2360 KB |
Output is correct |
5 |
Correct |
29 ms |
2416 KB |
Output is correct |
6 |
Correct |
29 ms |
2348 KB |
Output is correct |
7 |
Correct |
29 ms |
2404 KB |
Output is correct |
8 |
Correct |
404 ms |
63292 KB |
Output is correct |
9 |
Correct |
401 ms |
63136 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
29 ms |
2388 KB |
Output is correct |
12 |
Correct |
116 ms |
9892 KB |
Output is correct |
13 |
Correct |
113 ms |
9812 KB |
Output is correct |
14 |
Correct |
112 ms |
9804 KB |
Output is correct |
15 |
Correct |
115 ms |
9860 KB |
Output is correct |
16 |
Correct |
61 ms |
5964 KB |
Output is correct |
17 |
Correct |
61 ms |
5948 KB |
Output is correct |
18 |
Correct |
90 ms |
7840 KB |
Output is correct |
19 |
Correct |
117 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
416 ms |
63172 KB |
Output is correct |
2 |
Correct |
398 ms |
63172 KB |
Output is correct |
3 |
Correct |
408 ms |
63172 KB |
Output is correct |
4 |
Correct |
405 ms |
63060 KB |
Output is correct |
5 |
Correct |
462 ms |
63244 KB |
Output is correct |
6 |
Correct |
409 ms |
63264 KB |
Output is correct |
7 |
Correct |
410 ms |
63216 KB |
Output is correct |
8 |
Correct |
439 ms |
63260 KB |
Output is correct |
9 |
Correct |
420 ms |
63168 KB |
Output is correct |
10 |
Correct |
409 ms |
63176 KB |
Output is correct |
11 |
Correct |
427 ms |
63164 KB |
Output is correct |
12 |
Correct |
385 ms |
63180 KB |
Output is correct |
13 |
Correct |
440 ms |
63188 KB |
Output is correct |
14 |
Correct |
411 ms |
63184 KB |
Output is correct |
15 |
Correct |
400 ms |
63192 KB |
Output is correct |
16 |
Correct |
466 ms |
63168 KB |
Output is correct |
17 |
Correct |
426 ms |
63168 KB |
Output is correct |
18 |
Correct |
485 ms |
63100 KB |
Output is correct |
19 |
Correct |
412 ms |
63164 KB |
Output is correct |
20 |
Correct |
585 ms |
63244 KB |
Output is correct |
21 |
Correct |
411 ms |
63168 KB |
Output is correct |
22 |
Correct |
444 ms |
63148 KB |
Output is correct |
23 |
Correct |
432 ms |
63172 KB |
Output is correct |
24 |
Correct |
426 ms |
63248 KB |
Output is correct |
25 |
Correct |
400 ms |
63168 KB |
Output is correct |
26 |
Correct |
424 ms |
63172 KB |
Output is correct |
27 |
Correct |
568 ms |
63176 KB |
Output is correct |
28 |
Correct |
415 ms |
63232 KB |
Output is correct |
29 |
Correct |
424 ms |
63272 KB |
Output is correct |
30 |
Correct |
395 ms |
63176 KB |
Output is correct |
31 |
Correct |
401 ms |
63176 KB |
Output is correct |
32 |
Correct |
417 ms |
66404 KB |
Output is correct |
33 |
Correct |
434 ms |
63192 KB |
Output is correct |
34 |
Correct |
431 ms |
63172 KB |
Output is correct |
35 |
Correct |
415 ms |
63316 KB |
Output is correct |
36 |
Correct |
389 ms |
63172 KB |
Output is correct |
37 |
Correct |
401 ms |
63140 KB |
Output is correct |
38 |
Correct |
389 ms |
63428 KB |
Output is correct |
39 |
Correct |
417 ms |
64192 KB |
Output is correct |
40 |
Correct |
454 ms |
66996 KB |
Output is correct |
41 |
Correct |
29 ms |
2388 KB |
Output is correct |
42 |
Correct |
30 ms |
2396 KB |
Output is correct |
43 |
Correct |
29 ms |
2320 KB |
Output is correct |
44 |
Correct |
29 ms |
2360 KB |
Output is correct |
45 |
Correct |
29 ms |
2416 KB |
Output is correct |
46 |
Correct |
29 ms |
2348 KB |
Output is correct |
47 |
Correct |
29 ms |
2404 KB |
Output is correct |
48 |
Correct |
404 ms |
63292 KB |
Output is correct |
49 |
Correct |
401 ms |
63136 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
29 ms |
2388 KB |
Output is correct |
52 |
Correct |
116 ms |
9892 KB |
Output is correct |
53 |
Correct |
113 ms |
9812 KB |
Output is correct |
54 |
Correct |
112 ms |
9804 KB |
Output is correct |
55 |
Correct |
115 ms |
9860 KB |
Output is correct |
56 |
Correct |
61 ms |
5964 KB |
Output is correct |
57 |
Correct |
61 ms |
5948 KB |
Output is correct |
58 |
Correct |
90 ms |
7840 KB |
Output is correct |
59 |
Correct |
117 ms |
9848 KB |
Output is correct |
60 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
61 |
Halted |
0 ms |
0 KB |
- |