Submission #886558

#TimeUsernameProblemLanguageResultExecution timeMemory
886558vjudge1Towers (NOI22_towers)C++17
100 / 100
773 ms129040 KiB
#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) { debug(i, 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 = mx = i; } else if (X[mn] > X[i]) { debug(mn, mx, X[mn], X[i]); if (mx != mn) rem.push_back(mn); mn = i; } else if (X[mx] < X[i]) { debug(mx, mn, X[mx], X[i]); if (mx != mn) rem.push_back(mx); mx = i; } if (mn != i && mx != i) { debug("!used", i); rem.push_back(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 (int it = 0; it < int(rem.size()); ++it) { int i = rem[it]; debug(i, bool(top[i]), bool(bot[i])); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...