QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#111574 | #5504. Flower Garden | AK_Dream | RE | 7ms | 41552kb | C++14 | 2.6kb | 2023-06-07 16:35:52 | 2023-06-07 16:35:57 |
Judging History
answer
#include <bits/stdc++.h>
#define N 1000005
#define pb push_back
using namespace std;
template <typename T>
inline void read(T &num) {
T x = 0, ff = 1; char ch = getchar();
for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') ff = -1;
for (; ch <= '9' && ch >= '0'; ch = getchar()) x = (x<<3)+(x<<1)+(ch^'0');
num = x * ff;
}
int n, Q, tot;
int lc[N], rc[N];
int dfn[N], low[N], stk[N], in[N], col[N], siz[N], top, tme, scc;
vector<int> E[N];
void build(int &p, int l, int r, int tp) {
if (l == r) return p=l, void();
p = ++tot; E[p].clear();
int mid = (l+r)>>1;
build(lc[p],l,mid,tp); build(rc[p],mid+1,r,tp);
if (!tp) E[lc[p]].pb(p), E[rc[p]].pb(p);
else E[p].pb(lc[p]), E[p].pb(rc[p]);
}
void qry(int p, int l, int r, int x, int y, int v, int tp) {
if (x <= l && r <= y) {
if (!tp) E[p].pb(v); else E[v].pb(p);
return;
}
int mid = (l+r)>>1;
if (x <= mid) qry(lc[p],l,mid,x,y,v,tp);
if (mid < y) qry(rc[p],mid+1,r,x,y,v,tp);
}
void tarjan(int x) {
dfn[x] = low[x] = ++tme;
stk[++top] = x; in[x] = 1;
for (auto y : E[x]) {
if (!dfn[y]) tarjan(y), low[x] = min(low[x], low[y]);
else if (in[y]) low[x] = min(low[x], dfn[y]);
}
if (dfn[x] == low[x]) {
int z = 0; siz[++scc] = 0;
do {
z = stk[top--];
in[z] = 0; col[z] = scc;
if (z <= n) ++siz[scc];
} while (z != x);
}
}
void dfs(int x, int &sum) {
if (x <= n) ++sum;
dfn[x] = 0;
for (auto y : E[x]) if (dfn[y]) dfs(y, sum);
}
void solve() {
read(n); read(Q); n *= 3;
tot = n;
for (int i = 1; i <= n; i++) E[i].clear();
int rt0 = 0, rt1 = 0;
build(rt0,1,n,0); build(rt1,1,n,1);
while (Q--) {
int l, r, x, y; read(l); read(r); read(x); read(y);
int t = ++tot; E[t].clear();
qry(rt0,1,n,l,r,t,0); qry(rt1,1,n,x,y,t,1);
}
for (int i = 1; i <= tot; i++) dfn[i] = 0;
tme = scc = 0;
for (int i = 1; i <= tot; i++) if (!dfn[i]) tarjan(i);
int k = 0, sum = 0;
for (int i = 1; i <= scc; i++) {
sum += siz[i];
if (sum >= n/3) {
if (sum <= 2*n/3) k = i;
else assert(siz[i] >= n/3), k = -i;
break;
}
}
if (k > 0) {
puts("TAK"); sum = 0;
for (int i = 1; i <= n; i++) putchar(col[i]<=k?'F':'R'), sum += (col[i]<=k);
putchar('\n'); return;
}
assert(sum == n);
k = -k;
for (int i = 1; i <= tot; i++) if (col[i] == k) {
sum = 0; dfs(k, sum);
if (sum > 2*n/3) { puts("NIE"); return; }
puts("TAK"); sum = 0;
for (int j = 1; j <= n; j++) putchar(!dfn[j]?'F':'R'), sum += (!dfn[j]);
putchar('\n'); return;
}
}
int main() {
int ttt; read(ttt);
while (ttt--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 7ms
memory: 41552kb
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: -100
Dangerous Syscalls
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...