forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
birdrescue.cpp
62 lines (50 loc) · 1.25 KB
/
birdrescue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
int manhattan(int x1, int y1, int x2, int y2) {
return abs(x1-x2) + abs(y1-y2);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n, q;
cin >> n >> q;
int px, py;
cin >> px >> py;
vector<int> dist(2000002, 0);
for(int i = 0; i < n; i++) {
vector<int> x(2);
vector<int> y(2);
cin >> x[0] >> y[0] >> x[1] >> y[1];
sort(x.begin(), x.end());
sort(y.begin(), y.end());
if(x[0] <= px && px <= x[1]) {
x.push_back(px);
}
if(y[0] <= py && py <= y[1]) {
y.push_back(py);
}
vector<int> dists;
for(auto j : x) {
for(auto k : y) {
dists.push_back(manhattan(j, k, px, py));
}
}
sort(dists.begin(), dists.end());
if(dists.front() <= 2000001) {
dist[dists.front()]++;
}
if(dists.back() <= 2000000) {
dist[dists.back()+1]--;
}
}
int sum = 0;
for(int i = 0; i < dist.size(); i++) {
sum += dist[i];
dist[i] = sum;
}
for(int i = 0; i < q; i++) {
int t;
cin >> t;
cout << dist[t] << endl;
}
}