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 namespace std;
template<typename A, typename B>
string to_string(pair<A, B>);
string to_string(string S) {
return '"' + S + '"';
}
string to_string(const char* c) {
return to_string(string(c));
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template<size_t T>
string to_string(bitset<T> bs) {
return bs.to_string();
}
string to_string(vector<bool> v) {
string res = "{";
for (int i = 0; i < int(v.size()); ++i) {
if (int(res.size()) > 1) {
res += ", ";
}
res += to_string(v[i]);
}
return res + "}";
}
template<typename T>
string to_string(T v) {
string res = "{";
for (auto e : v) {
if (int(res.size()) > 1) {
res += ", ";
}
res += to_string(e);
}
return res + "}";
}
template<typename A, typename B>
string to_string(pair<A, B> p) {
return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
void debug_out() {
cerr << endl;
}
template<typename H, typename... T>
void debug_out(H head, T... tail) {
cerr << " " << to_string(head);
debug_out(tail...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(37)
#endif
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> X(N), Y(N);
for (int i = 0; i < N; ++i) {
cin >> X[i] >> Y[i];
--X[i], --Y[i];
}
#ifdef LOCAL
const int MAX = int(30);
#else
const int MAX = int(1e6);
#endif
vector<vector<int>> xs(MAX), ys(MAX);
for (int i = 0; i < N; ++i) {
xs[X[i]].push_back(i);
ys[Y[i]].push_back(i);
}
vector<int> xid(N), yid(N);
for (int i = 0; i < MAX; ++i) {
sort(xs[i].begin(), xs[i].end(), [&](int x, int y) {
return Y[x] < Y[y];
});
sort(ys[i].begin(), ys[i].end(), [&](int x, int y) {
return X[x] < X[y];
});
for (int j = 0; j < int(xs[i].size()); ++j) {
xid[xs[i][j]] = j;
}
for (int j = 0; j < int(ys[i].size()); ++j) {
yid[ys[i][j]] = j;
}
}
vector<bool> top(N), bot(N);
vector<int> min_row(MAX, -1);
vector<int> max_row(MAX, -1);
vector<int> rem;
auto Add = [&](int i, bool type) {
if (type) {
top[i] = true;
} else {
bot[i] = true;
}
int& mn = min_row[Y[i]];
int& mx = max_row[Y[i]];
if (mn == -1) {
mn = i;
}
if (mx == -1) {
mx = i;
}
if (X[mn] > X[i]) {
if (mx != mn) rem.push_back(mn);
mn = i;
}
if (X[mx] < X[i]) {
if (mx != mn) rem.push_back(mx);
mx = i;
}
};
for (int i = 0; i < MAX; ++i) {
if (xs[i].empty()) continue;
Add(xs[i][0], false);
Add(xs[i].back(), true);
}
debug(top, bot, rem);
for (auto i : rem) {
if (top[i] && bot[i]) {
top[i] = bot[i] = false;
continue;
}
if (top[i]) {
top[i] = false;
Add(xs[X[i]][xid[i] - 1], true);
} else if (bot[i]) {
bot[i] = false;
Add(xs[X[i]][xid[i] + 1], false);
}
}
for (int i = 0; i < N; ++i) {
cout << (bot[i] || top[i]);
}
cout << '\n';
}
# | 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... |