QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#474649 | #5504. Flower Garden | rainygame | WA | 2350ms | 399556kb | C++14 | 2.8kb | 2024-07-12 21:42:26 | 2024-07-12 21:42:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000005
int t, n, m, k, vct, sct, cnt;
int dfn[MAXN], low[MAXN], scc[MAXN];
int val[MAXN]; bool vis[MAXN], ans[MAXN];
stack<int, list<int>> st;
vector<int> e[MAXN], g[MAXN];
void addeg(int u, int v){
e[u].push_back(v);
g[v].push_back(u);
// cout << u << ' ' << v << '\n';
}
namespace Seg{
int idx[MAXN], idy[MAXN]; // idx:进 idy:出
void build(int p, int l, int r){
if (l == r){idx[p]=idy[p]=l; return;}
int mid((l+r)>>1); build(p<<1, l, mid); build(p<<1|1, mid+1, r);
idx[p] = ++vct; idy[p] = ++vct;
addeg(idx[p], idx[p<<1]); addeg(idx[p], idx[p<<1|1]);
addeg(idy[p<<1], idy[p]); addeg(idy[p<<1|1], idy[p]);
}
void conct(int p, int l, int r, int L, int R, int x, bool opt){
if (L <= l && r <= R){
if (opt) addeg(idy[p], x);
else addeg(x, idx[p]);
return;
}
int mid((l+r)>>1);
if (L <= mid) conct(p<<1, l, mid, L, R, x, opt);
if (R > mid) conct(p<<1|1, mid+1, r, L, R, x, opt);
}
}
void tarjan(int x){
dfn[x] = low[x] = ++cnt;
st.push(x); vis[x] = 1;
for (auto i: e[x]){
if (!dfn[i]){tarjan(i); low[x] = min(low[x], low[i]);}
else if (vis[i]) low[x] = min(low[x], dfn[i]);
}
if (dfn[x] == low[x]){
scc[x] = ++sct; vis[x] = 0;
for (; st.top() ^ x; st.pop()){scc[st.top()] = sct; vis[st.top()] = 0;}
st.pop();
}
}
int dfs(int x, bool k){ // k = 1 搜前缀 k = 0 搜后缀
if (ans[x]) return 0;
ans[x] = 1; int sz(x <= n);
if (!k) for (auto i: e[x]) sz += dfs(i, 0);
else for (auto i: g[x]) sz += dfs(i, 1);
return sz;
}
bool calc(){
for (int i(1); i<=n; ++i) ++val[scc[i]];
for (int i(1), res(0), ps(0); i<=sct; ++i){
res += val[i];
if (res > 2*k){
for (int j(1); j<=n; ++j) if (scc[j] == i) ps = j;
for (int j(1); j<=vct; ++j) ans[j] = 0;
if (dfs(ps, 1) <= 2*k){
for (int i(1); i<=n; ++i) ans[i] ^= 1;
return true;
}
for (int i(1); i<=vct; ++i) ans[i] = 0;
return dfs(ps, 0) <= 2*k;
}else if (res >= k){
for (int j(1); j<=n; ++j) ans[j] = scc[j] <= i;
return true;
}
}
return false;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (cin >> t; t; --t){
cin >> k >> m; vct = n = k*3; Seg::build(1, 1, n);
for (int lx, rx, ly, ry; m; --m){
cin >> lx >> rx >> ly >> ry;
Seg::conct(1, 1, n, lx, rx, ++vct, 1); Seg::conct(1, 1, n, ly, ry, vct, 0);
}
for (int i(1); i<=n; ++i) if (!dfn[i]) tarjan(i);
// cout << sct << '\n';
if (!calc()) cout << "NIE\n";
else{
cout << "TAK\n";
for (int i(1); i<=n; ++i) cout << (ans[i] ? 'F' : 'R'); cout << '\n';
}
cnt = vct = sct = 0;
for (int i(1); i<=vct; ++i){
e[i].clear(); g[i].clear();
dfn[i] = low[i] = val[i] = 0;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 52812kb
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: 2350ms
memory: 399556kb
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: 1654ms
memory: 281384kb
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 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...
result:
wrong answer zla odpowiedz!