Submission #886534

#TimeUsernameProblemLanguageResultExecution timeMemory
886534vjudge1Towers (NOI22_towers)C++17
18 / 100
821 ms121168 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> used(N), only(N); for (int i = 0; i < MAX; ++i) { if (xs[i].empty()) continue; used[xs[i][0]] = true; used[xs[i].back()] = true; if (xs[i].size() == 1) { only[xs[i][0]] = true; } } debug(used); for (int i = MAX - 1; i > 0; --i) { vector<int> act; for (auto x : ys[i]) { if (used[x]) { act.push_back(x); } } debug(act); for (int j = 1; j < int(act.size()) - 1; ++j) { int e = act[j]; used[e] = false; debug(e); if (!only[e]) { debug(xs[X[e]]); int prev = xid[e] - 1; if (prev >= 0) { int go = xs[X[e]][prev]; if (used[go]) { only[go] = true; } else { used[go] = true; } } } } } debug(used); for (int i = 0; i < MAX; ++i) { vector<int> act; for (auto x : ys[i]) { if (used[x]) { act.push_back(x); } } for (int j = 1; j < int(act.size()) - 1; ++j) { int e = act[j]; used[e] = false; if (!only[e]) { int prev = xid[e] + 1; assert(prev < int(xs[X[e]].size())); int go = xs[X[e]][prev]; if (used[go]) { only[go] = true; } else { used[go] = true; } } } } for (int i = 0; i < N; ++i) { cout << used[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...