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 nl "\n"
#define no "NO"
#define yes "YES"
#define fi first
#define se second
#define vec vector
#define task "main"
#define _mp make_pair
#define ii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define evoid(val) return void(std::cout << val)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FOD(i, b, a) for(int i = (b); i >= (a); --i)
#define unq(x) sort(all(x)); x.resize(unique(all(x)) - x.begin())
using namespace std;
template<typename U, typename V> bool maxi(U &a, V b) {
if (a < b) { a = b; return 1; } return 0;
}
template<typename U, typename V> bool mini(U &a, V b) {
if (a > b) { a = b; return 1; } return 0;
}
const int mod = (int)1e9 + 7;
void prepare(); void main_code();
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
const bool MULTITEST = 0; prepare();
int num_test = 1; if (MULTITEST) cin >> num_test;
while (num_test--) { main_code(); }
}
void prepare() {};
const int N = (int)1e6 + 9;
struct point {
int x, y;
};
point a[N];
pair<int, int> b[N];
vector<int> row[N];
vec<int> col[N];
void _fill(int rw, int j) {
int c = a[j].x;
col[c].push_back(j);
sort(all(col[c]), [&](int x, int y){
return a[x].y < a[y].y;
});
if (sz(col[c]) == 3) {
swap(col[c][1], col[c][2]);
int t = col[c].back();
col[c].pop_back();
int nw = a[t].y;
int &l = b[nw].fi, &r = b[nw].se;
if (row[nw][l] == t) {
++l;
if (l<r)
_fill(nw, row[nw][l]);
} else {
--r;
if (r>l)
_fill(nw, row[nw][r]);
}
}
}
void main_code() {
int n; cin >> n;
vec<int> yy;
for(int i = 0; i < n; ++i) {
cin >> a[i].x >> a[i].y;
row[a[i].y].push_back(i);
}
const int MAX = N - 3;
FOR(i, 0, MAX) if (sz(row[i])) {
sort(row[i].begin(), row[i].end(), [&](int x, int y) {
return a[x].x < a[y].x;
});
int m = sz(row[i]);
b[i] = _mp(0, m - 1);
_fill(i, row[i][0]);
if (m != 1)
_fill(i, row[i][m - 1]);
}
vec<bool> use(n, 0);
FOR(i, 0, MAX) if (sz(row[i])) {
int l=b[i].fi, r=b[i].se;
if (l<=r){
use[row[i][l]]=use[row[i][r]]=1;
}
}
string s;
FOR(i,0,n-1){
if(use[i])s.push_back('1');
else s.push_back('0');
}
cout << s;
}
/* Let the river flows naturally */
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen(task".out", "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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |