QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#470052#5504. Flower GardenYansuan_HClWA 4ms28412kbC++143.4kb2024-07-10 09:55:122024-07-10 09:55:13

Judging History

你现在查看的是最新测评结果

  • [2024-07-10 09:55:13]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:28412kb
  • [2024-07-10 09:55:12]
  • 提交

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 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;
	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);
		} 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;
		}
	}
	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;
		si1.connect(a, b, p);
		so1.connect(c, d, p);
	}
	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: 0
Wrong Answer
time: 4ms
memory: 28412kb

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
FRR
NIE

result:

wrong answer odpowiedz nie spelnia wymogow!