This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;
constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;
random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());
template<typename T>
bool assign_max(T& a, T b) {
if (b > a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool assign_min(T& a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
T square(T a) {
return a * a;
}
template<>
struct std::hash<pair<ll, ll>> {
ll operator() (pair<ll, ll> p) const {
return ((__int128)p.first * MOD + p.second) % INF64;
}
};
ll gmaxpreff(vector<pair<ll, ll>>& all, ll s) {
ll nx = all.begin()->first;
ll miny = INF32, maxy = -INF32;
auto now = all.begin();
while (now != all.end()) {
auto[x, y] = *now;
if (x - nx > s) {
return x;
}
assign_min(miny, y);
assign_max(maxy, y);
if (maxy - miny > s) {
return x;
}
now++;
}
return INF32;
}
ll gmaxsufff(vector<pair<ll, ll>>& all, ll s) {
ll nx = all.rbegin()->first;
ll miny = INF32, maxy = -INF32;
auto now = all.rbegin();
while (now != all.rend()) {
auto[x, y] = *now;
if (nx - x > s) {
return x;
}
assign_min(miny, y);
assign_max(maxy, y);
if (maxy - miny > s) {
return x;
}
now++;
}
return -INF32;
}
ll gmaxprefs(vector<pair<ll, ll>>& all, ll s) {
ll nx = all.begin()->second;
ll miny = INF32, maxy = -INF32;
auto now = all.begin();
while (now != all.end()) {
auto[y, x] = *now;
if (x - nx > s) {
return x;
}
assign_min(miny, y);
assign_max(maxy, y);
if (maxy - miny > s) {
return x;
}
now++;
}
return INF32;
}
ll gmaxsuffs(vector<pair<ll, ll>>& all, ll s) {
ll nx = all.rbegin()->second;
ll miny = INF32, maxy = -INF32;
auto now = all.rbegin();
while (now != all.rend()) {
auto[y, x] = *now;
if (nx - x > s) {
return x;
}
assign_min(miny, y);
assign_max(maxy, y);
if (maxy - miny > s) {
return x;
}
now++;
}
return -INF32;
}
pair<bool, vector<tuple<ll, ll, ll>>> s2h(ll s, vector<pair<ll, ll>>& arr, bool b = true) {
vector<tuple<ll, ll, ll>> ans;
if (arr.empty()) {
ans.emplace_back(2'500'000'000, 2'500'000'000, 1);
ans.emplace_back(3'000'000'000, 3'000'000'000, 1);
return make_pair(true, ans);
}
sort(arr.begin(), arr.end());
ll mpref = gmaxpreff(arr, s), msuff = gmaxsufff(arr, s);
if (mpref <= msuff) {
return make_pair(false, ans);
}
ll maxx1 = -INF32, minx1 = INF32;
ll maxy1 = -INF32, miny1 = INF32;
ll maxx2 = -INF32, minx2 = INF32;
ll maxy2 = -INF32, miny2 = INF32;
for (auto[x, y] : arr) {
if (x < mpref) {
assign_max(maxx1, x);
assign_min(minx1, x);
assign_max(maxy1, y);
assign_min(miny1, y);
} else {
assign_max(maxx2, x);
assign_min(minx2, x);
assign_max(maxy2, y);
assign_min(miny2, y);
}
}
if (b) {
ans.emplace_back(maxx1 - s, miny1, s);
ans.emplace_back(minx2, miny2, s);
} else {
ans.emplace_back(maxx1 - s, maxy1 - s, s);
ans.emplace_back(minx2, maxy2 - s, s);
}
return make_pair(true, ans);
}
bool cmp(pair<ll, ll> p1, pair<ll, ll> p2) {
return p1.second < p2.second;
}
pair<bool, vector<tuple<ll, ll, ll>>> s2v(ll s, vector<pair<ll, ll>>& arr, bool b = true) {
vector<tuple<ll, ll, ll>> ans;
if (arr.empty()) {
ans.emplace_back(2'500'000'000, 2'500'000'000, 1);
ans.emplace_back(3'000'000'000, 3'000'000'000, 1);
return make_pair(true, ans);
}
sort(arr.begin(), arr.end(), cmp);
ll mpref = gmaxprefs(arr, s), msuff = gmaxsuffs(arr, s);
if (mpref <= msuff) {
return make_pair(false, ans);
}
ll maxx1 = -INF32, minx1 = INF32;
ll maxy1 = -INF32, miny1 = INF32;
ll maxx2 = -INF32, minx2 = INF32;
ll maxy2 = -INF32, miny2 = INF32;
for (auto[x, y] : arr) {
if (y < mpref) {
assign_max(maxx1, x);
assign_min(minx1, x);
assign_max(maxy1, y);
assign_min(miny1, y);
} else {
assign_max(maxx2, x);
assign_min(minx2, x);
assign_max(maxy2, y);
assign_min(miny2, y);
}
}
if (b) {
ans.emplace_back(minx1, maxy1 - s, s);
ans.emplace_back(minx2, miny2, s);
} else {
ans.emplace_back(maxx1 - s, maxy1 - s, s);
ans.emplace_back(maxx2 - s, miny2, s);
}
return make_pair(true, ans);
}
pair<bool, vector<tuple<ll, ll, ll>>> s3hl(ll s, vector<pair<ll, ll>>& arr) {
sort(arr.begin(), arr.end());
ll mpref = gmaxpreff(arr, s);
vector<pair<ll, ll>> narr;
ll maxx = -INF32, minx = INF32;
ll maxy = -INF32, miny = INF32;
for (auto[x, y] : arr) {
if (x < mpref) {
assign_max(maxx, x);
assign_min(minx, x);
assign_max(maxy, y);
assign_min(miny, y);
} else {
narr.emplace_back(x, y);
}
}
vector<tuple<ll, ll, ll>> ans;
ans.emplace_back(maxx - s, maxy - s, s);
auto[f, nans] = s2v(s, narr, true);
if (!f) {
return make_pair(false, nans);
}
for (auto i : nans) {
ans.push_back(i);
}
return make_pair(true, ans);
}
pair<bool, vector<tuple<ll, ll, ll>>> s3hr(ll s, vector<pair<ll, ll>>& arr) {
sort(arr.begin(), arr.end());
ll msuff = gmaxsufff(arr, s);
vector<pair<ll, ll>> narr;
ll maxx = -INF32, minx = INF32;
ll maxy = -INF32, miny = INF32;
for (auto[x, y] : arr) {
if (x > msuff) {
assign_max(maxx, x);
assign_min(minx, x);
assign_max(maxy, y);
assign_min(miny, y);
} else {
narr.emplace_back(x, y);
}
}
vector<tuple<ll, ll, ll>> ans;
ans.emplace_back(minx, miny, s);
auto[f, nans] = s2v(s, narr, false);
if (!f) {
return make_pair(false, nans);
}
for (auto i : nans) {
ans.push_back(i);
}
return make_pair(true, ans);
}
pair<bool, vector<tuple<ll, ll, ll>>> s3vl(ll s, vector<pair<ll, ll>>& arr) {
sort(arr.begin(), arr.end(), cmp);
ll mpref = gmaxprefs(arr, s);
vector<pair<ll, ll>> narr;
ll maxx = -INF32, minx = INF32;
ll maxy = -INF32, miny = INF32;
for (auto[x, y] : arr) {
if (y < mpref) {
assign_max(maxx, x);
assign_min(minx, x);
assign_max(maxy, y);
assign_min(miny, y);
} else {
narr.emplace_back(x, y);
}
}
vector<tuple<ll, ll, ll>> ans;
ans.emplace_back(maxx - s, maxy - s, s);
auto[f, nans] = s2h(s, narr, true);
if (!f) {
return make_pair(false, nans);
}
for (auto i : nans) {
ans.push_back(i);
}
return make_pair(true, ans);
}
pair<bool, vector<tuple<ll, ll, ll>>> s3vr(ll s, vector<pair<ll, ll>>& arr) {
sort(arr.begin(), arr.end(), cmp);
ll msuff = gmaxsuffs(arr, s);
vector<pair<ll, ll>> narr;
ll maxx = -INF32, minx = INF32;
ll maxy = -INF32, miny = INF32;
for (auto[x, y] : arr) {
if (y > msuff) {
assign_max(maxx, x);
assign_min(minx, x);
assign_max(maxy, y);
assign_min(miny, y);
} else {
narr.emplace_back(x, y);
}
}
vector<tuple<ll, ll, ll>> ans;
ans.emplace_back(minx, miny, s);
auto[f, nans] = s2h(s, narr, false);
if (!f) {
return make_pair(false, nans);
}
for (auto i : nans) {
ans.push_back(i);
}
return make_pair(true, ans);
}
void solve() {
ll n, k;
cin >> n >> k;
vector<pair<ll, ll>> arr(n);
for (ll i = 0; i < n; i++) {
cin >> arr[i].first >> arr[i].second;
}
if (k == 1) {
ll maxx = -INF32, minx = INF32;
ll maxy = -INF32, miny = INF32;
for (auto[x, y] : arr) {
assign_max(maxx, x);
assign_min(minx, x);
assign_max(maxy, y);
assign_min(miny, y);
}
cout << minx << ' ' << miny << ' ' << max(1ll, max(maxx - minx, maxy - miny)) << '\n';
return;
}
if (k == 2) {
ll l = 0, r = INF32;
while (r - l > 1) {
ll mid = (l + r) / 2;
if (s2h(mid, arr).first || s2v(mid, arr).first) {
r = mid;
} else {
l = mid;
}
}
if (s2h(r, arr).first) {
for (auto[a, b, c] : s2h(r, arr).second) {
cout << a << ' ' << b << ' ' << c << '\n';
}
} else {
for (auto[a, b, c] : s2v(r, arr).second) {
cout << a << ' ' << b << ' ' << c << '\n';
}
}
return;
}
ll l = 0, r = INF32;
while (r - l > 1) {
ll mid = (l + r) / 2;
if (s3hl(mid, arr).first || s3hr(mid, arr).first || s3vl(mid, arr).first || s3vr(mid, arr).first) {
r = mid;
} else {
l = mid;
}
}
if (s3hl(r, arr).first) {
for (auto[a, b, c] : s3hl(r, arr).second) {
cout << a << ' ' << b << ' ' << c << '\n';
}
return;
}
if (s3hr(r, arr).first) {
for (auto[a, b, c] : s3hr(r, arr).second) {
cout << a << ' ' << b << ' ' << c << '\n';
}
return;
}
if (s3vl(r, arr).first) {
for (auto[a, b, c] : s3vl(r, arr).second) {
cout << a << ' ' << b << ' ' << c << '\n';
}
return;
}
if (s3vr(r, arr).first) {
for (auto[a, b, c] : s3vr(r, arr).second) {
cout << a << ' ' << b << ' ' << c << '\n';
}
return;
}
}
int main() {
if (IS_FILE) {
freopen("", "r", stdin);
freopen("", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
if (IS_TEST_CASES) {
cin >> t;
}
for (ll i = 0; i < t; i++) {
solve();
}
}
Compilation message (stderr)
izvanzemaljci.cpp: In function 'int main()':
izvanzemaljci.cpp:397:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
397 | freopen("", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~
izvanzemaljci.cpp:398:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
398 | freopen("", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~
# | 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... |