QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85957 | #5689. 喵了个喵 II | Scintilla | RE | 0ms | 0kb | C++14 | 3.6kb | 2023-03-08 21:55:09 | 2023-03-08 21:55:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb emplace_back
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl
using pii = pair <int, int>;
const int N = 1e6 + 10;
int read() {
int x = 0, f = 1; char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
return x * f;
}
int n, m, p[N][4], cnt[N], ans[N];
vector <int> e[N];
// struct vec {
// int x, y, id;
// vec(int _x = 0, int _y = 0, int _id = 0) {
// x = _x, y = _y, id = _id;
// }
// friend bool operator < (vec a, vec b) {
// return a.x < b.x;
// }
// } a[N], b[N];
pii a[N], b[N];
int tot, val[N];
void cdq(int l, int r, int p, int q) {
if (l == r) return;
int mid = (l + r) >> 1;
auto id = [&](int i, int o) { return n * o + i; } ;
auto work = [&](pii *x, pii *y) {
tot = 0;
rep(i, l, mid) if (x[i].second) val[++ tot] = x[i].first;
rep(i, mid + 1, r) if (y[i].second) val[++ tot] = y[i].first;
sort(val + 1, val + tot + 1);
tot = unique(val + 1, val + tot + 1) - val - 1;
rep(i, l, mid) if (x[i].second) {
int k = lower_bound(val + 1, val + tot + 1, x[i].first) - val;
e[id(x[i].second, p)].pb(m + k);
}
rep(i, mid + 1, r) if (y[i].second) {
int k = lower_bound(val + 1, val + tot + 1, y[i].first) - val;
e[m + k].pb(id(y[i].second, !q));
}
m += tot;
rep(i, l, mid) if (x[i].second) {
int k = lower_bound(val + 1, val + tot + 1, x[i].first) - val;
e[m + k].pb(id(x[i].second, !p));
}
rep(i, mid + 1, r) if (y[i].second) {
int k = lower_bound(val + 1, val + tot + 1, y[i].first) - val;
e[id(y[i].second, q)].pb(m + k);
}
m += tot;
} ;
work(a, b);
work(b, a);
cdq(l, mid, p, q);
cdq(mid + 1, r, p, q);
}
int dfn[N], dn, low[N], top, st[N], col[N], cn;
void tarjan(int u) {
dfn[u] = low[u] = ++ dn, st[++ top] = u;
for (int v : e[u]) {
if (!dfn[v]) tarjan(v), low[u] = min(low[u], low[v]);
else if (!col[v]) low[u] = min(low[u], dfn[v]);
}
if (low[u] == dfn[u]) {
for (++ cn; st[top + 1] != u; -- top) col[st[top]] = cn;
}
}
int main() {
n = read(), m = 2 * n;
rep(i, 1, n << 2) {
int x = read();
p[x][cnt[x] ++] = i;
}
rep(u, 0, 1) rep(v, 0, 1) {
rep(i, 1, n << 2) a[i] = b[i] = {0, 0};
rep(i, 1, n) {
a[p[i][0]] = {p[i][1 + u], i};
b[p[i][0]] = {p[i][1 + v], i};
}
cdq(1, n << 2, u, v);
rep(i, 1, n << 2) a[i] = b[i] = {0, 0};
rep(i, 1, n) {
a[p[i][0]] = {p[i][1 + u], i};
b[p[i][2 - v]] = {p[i][3], i};
}
cdq(1, n << 2, u, v);
rep(i, 1, n << 2) a[i] = b[i] = {0, 0};
rep(i, 1, n) {
a[p[i][2 - u]] = {p[i][3], i};
b[p[i][0]] = {p[i][1 + v], i};
}
cdq(1, n << 2, u, v);
rep(i, 1, n << 2) a[i] = b[i] = {0, 0};
rep(i, 1, n) {
a[p[i][2 - u]] = {p[i][3], i};
b[p[i][2 - v]] = {p[i][3], i};
}
cdq(1, n << 2, u, v);
}
rep(i, 1, m) if (!dfn[i]) tarjan(i);
rep(i, 1, n) if (col[i] == col[n + i]) return printf("No\n"), 0;
printf("Yes\n");
rep(i, 1, n) ans[p[i][0]] = ans[p[i][2 - (col[i] > col[n + i])]] = 1;
rep(i, 1, n << 2) printf("%d", ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
50000 12725 41478 2443 1096 36968 36898 3393 45898 43154 26629 22985 37972 13935 25628 40196 40293 39791 29109 455 45812 12634 21086 8928 13600 25416 30244 15917 22568 35849 40189 27442 28785 46334 25651 7172 30994 39724 27853 47091 21306 42087 31612 22081 23002 17127 15269 11569 8254 41080 30112 31...