QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#439874 | #5504. Flower Garden | alpha1022 | WA | 3ms | 32116kb | C++14 | 3.1kb | 2024-06-12 20:01:05 | 2024-06-12 20:01:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 33333;
const int M = 1e5;
const int S = N * 3 + (N * 6 - 1) * 2 + M;
int n, m, tot;
vector<int> g[S + 5], e[S + 5];
int dfn[S + 5], low[S + 5], stk[S + 5], top, dfnTot;
int scc[S + 5], siz[S + 5], sccTot;
bool inStk[S + 5];
void dfs(int u) {
dfn[u] = low[u] = ++dfnTot, inStk[stk[++top] = u] = 1;
for (int v : g[u])
if (!dfn[v]) dfs(v), low[u] = min(low[u], low[v]);
else if (inStk[v]) low[u] = min(low[u], dfn[v]);
if (dfn[u] == low[u]) {
++sccTot;
do scc[stk[top]] = sccTot, inStk[stk[top]] = 0;
while (stk[top--] != u);
}
}
int id[2][N * 3 * 4 + 5];
#define ls (u << 1)
#define rs (ls | 1)
void build(int u, int tl, int tr) {
id[0][u] = ++tot, id[1][u] = ++tot;
if (tl == tr) { g[tl].push_back(id[0][u]), g[id[1][u]].push_back(tl); return ; }
int mid = (tl + tr) >> 1;
build(ls, tl, mid), build(rs, mid + 1, tr);
g[id[0][ls]].push_back(id[0][u]), g[id[0][rs]].push_back(id[0][u]),
g[id[1][u]].push_back(id[1][ls]), g[id[1][u]].push_back(id[1][rs]);
}
template<class T>
void query(int l, int r, const T &func, int u, int tl, int tr) {
if (l <= tl && tr <= r) return func(u);
int mid = (tl + tr) >> 1;
if (l <= mid) query(l, r, func, ls, tl, mid);
if (r > mid) query(l, r, func, rs, mid + 1, tr);
}
#undef ls
#undef rs
int sum;
bool vis[S + 5], flag;
void solve() {
scanf("%d%d", &n, &m), tot = n * 3, fill_n(g + 1, n * 3 + (n * 6 - 1) * 2 + m, vector<int>());
build(1, 1, n * 3);
for (int i = 1; i <= m; ++i) {
int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d), ++tot;
query(a, b, [&](int u) { g[id[0][u]].push_back(tot); }, 1, 1, n * 3),
query(c, d, [&](int u) { g[tot].push_back(id[1][u]); }, 1, 1, n * 3);
}
fill_n(dfn + 1, tot, 0), dfnTot = sccTot = 0;
for (int i = 1; i <= tot; ++i) if (!dfn[i]) dfs(i);
fill_n(siz + 1, sccTot, 0);
for (int i = 1; i <= n * 3; ++i) ++siz[scc[i]];
fill_n(e + 1, sccTot, vector<int>());
for (int u = 1; u <= tot; ++u)
for (int v : g[u])
if (scc[u] != scc[v]) e[scc[u]].push_back(scc[v]);
sum = flag = 0, fill_n(vis + 1, sccTot, 0);
for (int u = sccTot; u; --u) {
if (siz[u] >= n) continue;
sum += siz[u], vis[u] = 1;
if (sum >= n && sum <= n * 2) { flag = 1; break; }
}
if (!flag) {
for (int s = 1; s <= sccTot; ++s) {
if (siz[s] < n) continue;
fill_n(vis + 1, sccTot, 0), sum = 0, vis[s] = 1;
for (int u = sccTot; u; --u)
for (int v : e[u]) vis[v] |= vis[u];
for (int u = 1; u <= sccTot; ++u) if (vis[u]) sum += siz[u];
if (sum >= n && sum <= n * 2) { flag = 1; break; }
fill_n(vis + 1, sccTot, 1), sum = 0, vis[s] = 0;
for (int u = 1; u <= sccTot; ++u)
for (int v : e[u]) vis[u] |= vis[v];
for (int u = 1; u <= sccTot; ++u) if (vis[u]) sum += siz[u];
if (sum >= n && sum <= n * 2) { flag = 1; break; }
}
}
if (!flag) puts("NIE");
else {
puts("TAK");
for (int i = 1; i <= n * 3; ++i) putchar("FR"[vis[scc[i]]]);
puts("");
}
}
int T;
int main() { for (scanf("%d", &T); T; --T) solve(); }
詳細信息
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 32116kb
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 FFR NIE
result:
wrong answer odpowiedz nie spelnia wymogow!