QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#99102 | #5504. Flower Garden | Johnsonloy | RE | 12ms | 52644kb | C++14 | 5.3kb | 2023-04-21 10:48:04 | 2023-04-21 10:48:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
const int maxn = 1e6 + 10;
namespace IO {
void openfile() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
}
inline int read() {
int x = 0, f = 0;
char c = getchar();
while (!isdigit(c))
f |= c == '-', c = getchar();
while (isdigit(c))
x = x * 10 + c - '0', c = getchar();
if (f)
x = -x;
return x;
}
} // namespace IO
using namespace IO;
int tot, n, m;
int rt1, rt2;
int dfn[maxn], low[maxn], tim, vis[maxn], sta[maxn], top, cnt, bl[maxn];
int x[maxn], y[maxn], bian, in[maxn], sz[maxn], ans[maxn];
vector<int> e[maxn], pos[maxn];
void add(int xx, int yy) {
e[xx].push_back(yy);
x[++bian] = xx, y[bian] = yy;
}
struct node {
int l, r, ls, rs;
} t[maxn];
void build1(int& rt, int l, int r) {
if (!rt)
rt = ++tot;
t[rt] = {l, r};
if (l == r)
return;
int mid = (l + r) >> 1;
build1(t[rt].ls, l, mid), build1(t[rt].rs, mid + 1, r);
add(rt, t[rt].ls), add(rt, t[rt].rs);
}
void build2(int& rt, int l, int r) {
if (!rt)
rt = ++tot;
t[rt] = {l, r};
if (l == r)
return add(rt - rt2 + 1, rt), void();
int mid = (l + r) >> 1;
build2(t[rt].ls, l, mid), build2(t[rt].rs, mid + 1, r);
add(t[rt].ls, rt), add(t[rt].rs, rt);
}
void init() {
for (int i = 1; i <= tot; i++)
t[i] = {0, 0, 0, 0}, dfn[i] = low[i] = bl[i] = in[i] = sz[i] = 0;
tot = tim = bian = cnt = top = rt1 = rt2 = 0;
}
void jia1(int rt, int l, int r, int x, int y, int d) {
if (x <= l && r <= y)
return add(d, rt), void();
int mid = (l + r) >> 1;
if (x <= mid)
jia1(t[rt].l, l, mid, x, y, d);
if (mid < y)
jia1(t[rt].r, mid + 1, r, x, y, d);
}
void jia2(int rt, int l, int r, int x, int y, int d) {
if (x <= l && r <= y)
return add(rt, d), void();
int mid = (l + r) >> 1;
if (x <= mid)
jia2(t[rt].l, l, mid, x, y, d);
if (mid < y)
jia2(t[rt].r, mid + 1, r, x, y, d);
}
void tarjan(int x) {
vis[x] = 1, sta[++top] = x;
low[x] = dfn[x] = ++tim;
for (auto v : e[x]) {
if (!dfn[v])
tarjan(v), low[x] = min(low[x], low[v]);
else if (vis[v])
low[x] = min(low[x], dfn[v]);
}
if (dfn[x] == low[x]) {
int y;
cnt++;
do {
y = sta[top--];
bl[y] = cnt;
vis[y] = 0;
} while (x != y);
}
}
void topo() {
queue<int> q;
for (int i = 1; i <= cnt; i++)
if (!in[i])
q.push(i);
while (!q.empty()) {
int x = q.front();
q.pop();
sta[++top] = x;
for (auto v : e[x]) {
in[v]--;
if (!in[v])
q.push(v);
}
}
}
void dfs(int x) {
int ans = sz[x];
vis[x] = 1;
for (auto v : e[x])
if (!vis[v])
dfs(v);
}
void solve() {
n = read(), m = read();
build1(rt1, 1, n * 3), build2(rt2, 1, n * 3);
for (int i = 1; i <= m; i++) {
int l1 = read(), r1 = read(), l2 = read(), r2 = read();
int d1 = ++tot, d2 = ++tot;
jia2(rt2, 1, n * 3, l1, r1, d1), jia1(rt1, 1, n * 3, l2, r2, d1);
jia2(rt2, 1, n * 3, l2, r2, d2), jia2(rt1, 1, n * 3, l1, r1, d2);
}
for (int i = 1; i <= tot; i++)
if (!dfn[i])
tarjan(i);
for (int i = 1; i <= tot; i++)
e[i].clear();
for (int i = 1; i <= bian; i++) {
if (bl[x[i]] == bl[y[i]])
continue;
e[bl[x[i]]].push_back(bl[y[i]]);
in[bl[y[i]]]++;
}
topo();
for (int i = 1; i < rt2; i++)
if (t[i].l == t[i].r)
++sz[bl[i]], pos[bl[i]].push_back(t[i].l);
int sum = 0, flag = 0;
for (int i = 1; i <= top; i++) {
sum += sz[i];
if (sum >= n && sum <= n * 2) {
flag = i;
break;
}
}
if (flag) {
for (int i = 1; i <= top; i++)
for (auto v : pos[i])
ans[v] = (i <= flag);
puts("TAK");
for (int i = 1; i <= n * 3; i++)
if (ans[i])
putchar('R');
else
putchar('F');
puts("");
return;
}
for (int i = 1; i <= top; i++)
if (sz[i] >= n) {
for (int i = 1; i <= n; i++)
vis[i] = 0;
int sum = 0;
for (int i = 1; i <= top; i++)
if (vis[i])
sum += sz[i];
if (sum >= n && sum <= n * 2) {
for (int i = 1; i <= top; i++)
for (auto v : pos[i])
ans[v] = vis[i];
puts("TAK");
for (int i = 1; i <= n * 3; ++i)
if (ans[i])
putchar('F');
else
putchar('R');
puts("");
return;
}
}
puts("NIE");
}
signed main() {
openfile();
int T = read();
while (T--)
init(), solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 52644kb
input:
2 1 3 1 1 2 2 1 2 3 3 1 1 3 3 1 3 1 1 2 2 2 2 3 3 3 3 1 1
output:
TAK RFF NIE
result:
ok good!
Test #2:
score: -100
Runtime Error
input:
10 33333 100000 28701 40192 93418 95143 95902 97908 78378 78461 36823 44196 22268 23996 23977 24786 33315 48829 83965 90411 4923 8445 20235 21177 32543 47454 29598 35414 72477 73049 2014 12632 42163 46466 64305 65518 98825 99552 32331 41625 92772 96224 26500 54122 76990 77126 18249 20335 31165 36080...
output:
TAK RFRFFRFFFFFFFFRFFFFFFFFFFFFRFFFFFFFFFFRFRFFFFRFFFFRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFRRRRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFRFFRFFRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...