This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using i64 = long long;
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> x(n), y(n);
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
while (q--) {
i64 k;
cin >> k;
sort(x.begin(), x.end());
auto calc = [&](i64 k) {
if (k % 2 == 0) {
i64 ans = 0;
for (int i = 0; i < n; i++) {
ans += (k + 1) * (k + 1) + k * k;
if (i + 1 < n && x[i + 1] - x[i] <= k) {
i64 f = k - (x[i + 1] - x[i]) + 1;
ans -= f * (k + 1);
ans -= (f - 1) * k;
}
}
return ans;
} else {
i64 ans = 0;
for (int i = 0; i < n; i++) {
ans += (k + 1) * (k + 1) + k * k;
if (i + 1 < n && x[i + 1] - x[i] <= k) {
i64 f = k - (x[i + 1] - x[i]) + 1;
ans -= f * (k + 1);
ans -= (f - 1) * k;
}
}
return ans;
}
};
if (k == 0) cout << n << "\n";
else {
cout << calc(k) - calc(k - 1) << "\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |