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>
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))
using namespace std;
const ll LINF = 4e18;
const int mxN = 1e6+10, A = 5e3+10, INF = 2e9;
ll n, m;
array<int, 2> a[mxN];
ll dist[A][A], cnt[2*A];
bool vis[A][A];
array<int, 2> dxdy[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
bool Valid(int i, int j){ return i >= 0 && i < A && j >= 0 && j < A && !vis[i][j]; }
void BF(){
queue<array<int, 2> > q;
for (int i = 0; i < n; i++){
auto [x, y] = a[i];
x += A/2; y += A/2;
q.push({x, y});
vis[x][y] = 1;
cnt[0]++;
}
while (q.size()){
auto [i, j] = q.front(); q.pop();
for (auto [dx, dy] : dxdy){
int x = i+dx, y = j+dy;
if (Valid(x, y)){
vis[x][y] = 1;
dist[x][y] = dist[i][j] + 1;
cnt[dist[x][y]]++;
q.push({x, y});
}
}
}
while (m--){
ri(t);
cout << cnt[t] << en;
}
}
ll b[mxN];
vector<ll> mrg;
void Solve1(){
for (int i = 0; i < n; i++)
b[i] = a[i][0];
sort(b, b+n);
for (int i = 0; i < n-1; i++)
mrg.pb(b[i+1] - b[i]);
sort(all(mrg));
int k = 0;
ll N = n, E = 0;
while (m--){
rl(t);
ll cnt = 0;
while (k < n-1 && mrg[k] <= t){
E += mrg[k]-1;
N--;
if (mrg[k] == t)
cnt++;
k++;
}
if (t) cout << 2LL*(n*(t+1) - (n-N)*t + E) + (2LL*N + cnt)*(t-1) << en;
else cout << n << en;
}
}
void Solve(){
cin >> n >> m;
bool f = 1;
for (int i = 0; i < n; i++){
cin >> a[i][0] >> a[i][1];
if (a[i][0] != a[i][1]) f = 0;
}
if (f) Solve1();
else BF();
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0); cerr.tie(0);
cout << setprecision(12) << fixed;
cerr << setprecision(12) << fixed;
cerr << "Started!" << endl;
int t = 1;
//cin >> t;
while (t--)
Solve();
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... |