QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#86029 | #5689. 喵了个喵 II | Scintilla | WA | 528ms | 168284kb | C++14 | 2.9kb | 2023-03-09 08:09:43 | 2023-03-09 08:09:47 |
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 = 2e6 + 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], cur[N], ans[N], cnt, tot, val[N];
vector <int> e[N];
struct node {
int x, y, id, o;
node(int _x = 0, int _y = 0, int _id = 0, int _o = 0) {
x = _x, y = _y, id = _id, o = _o;
}
friend bool operator < (node a, node b) {
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
} dat[N];
void cdq(int l, int r) {
if (l == r) return;
int mid = (l + r) >> 1;
auto id = [&](int i, int o) { return n * o + i; } ;
sort(dat + l, dat + r + 1);
// cout << "l, r = " << l << ' ' << r << endl;
sort(dat + l, dat + mid + 1, [&](node a, node b) { return a.y < b.y; });
sort(dat + mid + 1, dat + r + 1, [&](node a, node b) { return a.y < b.y; });
// rep(i, l, r) cout << dat[i].x << ' ' << dat[i].y << endl;
rep(i, l, mid) e[m + i - l + 1].pb(id(dat[i].id, !dat[i].o));
for (int i = l, j = mid + 1; i <= mid && j <= r; ++ i) {
while (i <= mid && dat[i].y <= dat[j].y) ++ i;
if (i > mid) break;
// cout << "i, j = " << i << ' ' << j << endl;
e[id(dat[i].id, dat[i].o)].pb(m + i - l + 1);
}
m += mid - l + 1;
// pv(m);
cdq(l, mid), cdq(mid + 1, r);
}
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;
for (int i = 1, x; i <= n << 2; ++ i) x = read(), p[x][cur[x] ++] = i;
rep(i, 1, n) {
dat[++ cnt] = node(p[i][0], p[i][1], i, 0);
dat[++ cnt] = node(p[i][2], p[i][3], i, 0);
dat[++ cnt] = node(p[i][0], p[i][2], i, 1);
dat[++ cnt] = node(p[i][1], p[i][3], i, 1);
}
// rep(i, 1, cnt) cout << dat[i].x << ' ' << dat[i].y << endl;
cdq(1, cnt);
// pv(m);
// rep(u, 1, m) {
// for (int v : e[u]) cout << u << ' ' << v << endl;
// }
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: 100
Accepted
time: 365ms
memory: 165300kb
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...
output:
Yes 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
ok correct
Test #2:
score: 0
Accepted
time: 402ms
memory: 168228kb
input:
50000 39298 39298 14319 14319 11620 11620 20424 20424 14345 14345 28478 28478 11587 11587 25545 25545 24607 24607 18203 18203 30593 30593 144 144 2117 2117 14201 14201 27012 27012 20683 20683 39367 39367 7902 7902 12365 12365 17601 17601 29145 29145 15133 15133 47765 47765 22205 22205 13706 13706 20...
output:
Yes 10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
result:
ok correct
Test #3:
score: 0
Accepted
time: 313ms
memory: 165452kb
input:
50000 21684 21684 49246 49246 20339 20339 12374 12374 25130 25130 30869 30869 21854 21854 19251 19251 24016 24016 4812 4812 13915 13915 14386 14386 33943 33943 43449 43449 16175 16175 29984 29984 4712 4712 48795 48795 952 952 3589 3589 34274 34274 12915 12915 6840 6840 23436 23436 15670 15670 3873 3...
output:
Yes 10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...
result:
ok correct
Test #4:
score: -100
Wrong Answer
time: 528ms
memory: 168284kb
input:
50000 236 236 32031 707 41062 32031 37516 21446 707 41062 37516 21446 26170 44004 47187 26170 9742 44004 47187 9742 14845 835 14845 43803 4270 835 43803 4270 44275 22853 44275 45825 5286 8810 10767 49050 26809 22853 36108 45825 46063 5286 6289 5206 8810 24938 33324 48973 10767 49050 49412 19286 4152...
output:
No
result:
wrong answer Incorrect