QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#470243 | #5504. Flower Garden | Yansuan_HCl | WA | 2867ms | 115292kb | C++14 | 4.1kb | 2024-07-10 11:34:06 | 2024-07-10 11:34:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define U(i,l,r) for (int i(l),END##i(r); i<=END##i; ++i)
#define D(i,l,r) for (int i(l),END##i(r); i>=END##i; --i)
#define ms(x, v) memset(x, v, sizeof(x))
#define il __attribute__((always_inline))
#define vc vector
#define ar array
#define pb push_back
#define eb emplace_back
#define el '\n'
using ll = long long;
const int N = 33335, M = 100005, V = N * 3 * 3 + M;
int n, Q, m; vc<int> g[V];
int ptr;
struct segt {
#define mid ((l + r) >> 1)
#define ls (p << 1)
#define rs (ls | 1)
#define ARG int p = 1, int l = 1, int r = m
vc<int> leaf; int bias; bool flag;
vc<ar<int, 2>> ch; vc<int> pt;
int build(ARG) {
int &u = pt[p]; pt[p] = ++ptr;
if (l == r) {
--ptr;
pt[p] = leaf[l] = bias + l;
return pt[p];
}
ch[p][0] = build(ls, l, mid);
ch[p][1] = build(rs, mid + 1, r);
if (flag) {
g[ch[p][0]].pb(u);
g[ch[p][1]].pb(u);
} else {
g[u].resize(2);
g[u][0] = ch[p][0];
g[u][1] = ch[p][1];
}
return u;
}
segt(bool _f, int _b) : bias(_b), flag(_f) {
leaf = vc<int>(m + 1);
ch = vc<ar<int, 2>>(m * 4 + 1);
pt = vc<int>(m * 4 + 1);
build();
}
void connect(int b, int e, int u, ARG) {
if (b <= l && e >= r) {
if (flag) g[pt[p]].pb(u);
else g[u].pb(pt[p]);
return;
}
if (b <= mid) connect(b, e, u, ls, l, mid);
if (e > mid) connect(b, e, u, rs, mid + 1, r);
}
};
int dfn[V], low[V], ins[V], stk[V], sp, col[V], dfp, cp, siz[N];
vc<int> scc[V];
void tarjan(int u) {
dfn[u] = low[u] = ++dfp;
ins[u] = 1; stk[++sp] = u;
// clog << "!" << u << endl;
assert(g[2].size());
for (int v : g[u])
if (!dfn[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
} else if (ins[v]) {
low[u] = min(low[u], dfn[v]);
}
if (dfn[u] == low[u]) {
int c = ++cp;
do {
col[stk[sp]] = c;
scc[c].pb(stk[sp]);
siz[c] += (stk[sp] <= m);
ins[stk[sp]] = 0;
} while (stk[sp--] != u);
}
}
bool cons() {
int c1 = 0; vc<int> vis(m + 1);
U (i, 1, cp) {
c1 += siz[i];
for (int v : scc[i]) if (v <= m)
vis[v] = 1;
if (c1 >= n)
break;
}
if (c1 > n * 2) return 0;
cout << "TAK\n";
U (i, 1, m)
cout << ("RF"[vis[i]]);
cout << el;
return 1;
}
void large() {
vc<vc<int>> h(cp + 1);
U (u, 1, ptr) for (int v : g[u]) if (col[u] != col[v])
h[col[u]].pb(col[v]);
U (i, 1, cp) if (siz[i] > n) {
vc<int> vip(m + 1), vic(cp + 1);
queue<int> q; vic[i] = 1; q.push(i);
int c1 = 0;
while (q.size()) {
int x = q.front(); q.pop();
for (int u : scc[x]) if (u <= m)
vip[u] = 1, ++c1;
for (int y : h[x]) if (!vic[y]) {
vic[y] = 1;
q.push(y);
}
}
if (c1 <= n * 2) {
cout << "TAK" << el;
U (u, 1, m)
cout << ("RF"[vip[u]]);
cout << el;
return;
}
}
h = vc<vc<int>>(cp + 1);
vc<int> in(cp + 1), vip(m + 1);
U (u, 1, ptr) for (int v : g[u]) if (col[u] != col[v]) {
h[col[v]].pb(col[u]);
++in[col[u]];
}
queue<int> q;
U (i, 1, cp) if (!in[i])
q.push(i);
int c1 = 0;
while (q.size()) {
int x = q.front(); q.pop();
for (int u : scc[x]) if (u <= m)
vip[u] = 1, ++c1;
if (c1 >= n) break;
for (int y : h[x]) if (!(--in[y]) && siz[y] <= n)
q.push(y);
}
if (c1 >= n) {
cout << "TAK" << el;
U (u, 1, m)
cout << ("RF"[vip[u]]);
cout << el;
return;
}
cout << "NIE" << el;
}
void solve() {
cin >> n >> Q;
m = ptr = n * 3;
segt si1(0, 0), so1(1, 0);
// clog << "fin" << endl;
U (i, 1, Q) {
int a, b, c, d, p; cin >> a >> b >> c >> d; p = ++ptr;
so1.connect(a, b, p);
si1.connect(c, d, p);
}
assert(g[2].size());
U (i, 1, ptr) if (!dfn[i])
tarjan(i);
bool f = cons();
if (!f)
large();
}
void clear() {
U (i, 1, ptr) g[i].clear();
U (i, 1, dfp)
dfn[i] = low[i] = ins[i] = stk[i] = col[i] = 0;
U (i, 1, cp) scc[i].clear(), siz[i] = 0;
dfp = cp = sp = 0;
}
int main() {
// freopen("arrebol.in", "r", stdin);
// freopen(".out", "w", stdout);
// ios::sync_with_stdio(0);
int t; cin >> t;
while (t--) {
solve();
clear();
}
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 28460kb
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 RRF NIE
result:
ok good!
Test #2:
score: 0
Accepted
time: 2867ms
memory: 115292kb
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:
NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE
result:
ok good!
Test #3:
score: -100
Wrong Answer
time: 2603ms
memory: 111792kb
input:
10 33333 100000 15207 33614 66276 66276 97173 97173 67589 73960 19673 36626 65207 65207 89825 98169 27079 27079 56067 56966 7560 7560 18170 35477 18752 18752 32621 36748 34460 34460 61595 61700 14117 14117 32395 36710 9064 9064 13172 13172 1728 4640 40462 41878 47171 47171 76965 82414 5767 5767 9225...
output:
TAK RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
result:
wrong answer odpowiedz ma za malo/duzo roz!