QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#392352#4000. Dynamic Reachability251SecWA 1236ms18224kbC++143.1kb2024-04-17 15:01:372024-04-17 15:01:37

Judging History

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

  • [2024-04-17 15:01:37]
  • 评测
  • 测评结果:WA
  • 用时:1236ms
  • 内存:18224kb
  • [2024-04-17 15:01:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int B = 512;
struct Oper {
	int op, x, y;
} ope[100005];
struct Edge {
	int u, v, nxt;
} e[100005];
int head[50005], len;
void Insert(int u, int v) {
	e[++len] = { u, v, head[u] };
	head[u] = len;
}
bool del[100005];
int n, m, q;
int dfn[50005], low[50005], bel[50005], cnt, cti, st[50005], top;
bool vis[50005], col[50005];
void Tarjan(int u) {
	dfn[u] = low[u] = ++cti;
	st[++top] = u, vis[u] = true;
	for (int i = head[u]; i; i = e[i].nxt) {
		if (del[i] || !col[i]) continue;
		int v = e[i].v;
		if (!dfn[v]) {
			Tarjan(v);
			low[u] = min(low[u], low[v]);
		}
		else if (vis[v]) low[u] = min(low[u], dfn[v]);
	}
	if (dfn[u] == low[u]) {
		cnt++;
		while (st[top + 1] != u) {
			int v = st[top--];
			vis[v] = false, bel[v] = cnt;
		}
	}
}
vector<int> eN[50005];
int id[50005], idR[50005], idC;
bitset<B * 2> tar[50005], cur[50005];
void InsP(int u) {
	u = bel[u];
	if (id[u] == -1) {
		id[u] = idC;
		idR[idC++] = u;
		tar[u].set(id[u]);
	}
}
int main() {
	scanf("%d%d%d", &n, &m, &q);
	for (int i = 1, u, v; i <= m; i++) {
		scanf("%d%d", &u, &v);
		Insert(u, v), col[i] = true;
	}
	for (int i = 1; i <= q; i++) {
		scanf("%d", &ope[i].op);
		if (ope[i].op == 1) scanf("%d", &ope[i].x);
		else scanf("%d%d", &ope[i].x, &ope[i].y);
	}
	for (int l = 1, r; l <= q; l += B) {
		r = min(l + B - 1, q);
		for (int i = l; i <= r; i++) if (ope[i].op == 1) del[ope[i].x] = true;
		memset(dfn, 0, sizeof(dfn)), memset(low, 0, sizeof(low)), memset(bel, 0, sizeof(bel)), memset(st, 0, sizeof(st)), memset(vis, 0, sizeof(vis));
		cnt = cti = top = 0;
		for (int i = 1; i <= n; i++) if (!dfn[i]) Tarjan(i);
		for (int i = 1; i <= n; i++) eN[i].clear();
		for (int u = 1; u <= n; u++) {
			for (int i = head[u]; i; i = e[i].nxt) {
				int v = e[i].v;
				if (!del[i] && col[i] && bel[u] != bel[v]) {
					eN[bel[u]].push_back(bel[v]);
				}
			}
		}
		memset(id, -1, sizeof(id)), idC = 0;
		for (int i = 1; i <= cnt; i++) tar[i].reset();
		for (int i = l; i <= r; i++) {
			if (ope[i].op == 1) {
				auto &x = e[ope[i].x];
				InsP(x.u), InsP(x.v);
			}
			else InsP(ope[i].x), InsP(ope[i].y);
		}
		for (int u = 1; u <= cnt; u++) {
			for (int v : eN[u]) tar[u] |= tar[v];
		}
		for (int i = l; i <= r; i++) {
			if (ope[i].op == 1) col[ope[i].x] ^= 1, del[ope[i].x] = false;
			else {
				for (int i = 0; i < idC; i++) cur[i] = tar[idR[i]];
				for (int i = l; i <= r; i++) {
					if (ope[i].op == 1) {
						if (col[ope[i].x]) {
							auto &x = e[ope[i].x];
							cur[id[bel[x.u]]].set(id[bel[x.v]]);
						}
					}
				}
				bitset<B * 2> nvis; nvis.set();
				queue<int> q;
				q.push(id[bel[ope[i].x]]), nvis.reset(id[bel[ope[i].x]]);
				while (!q.empty()) {
					int u = q.front(); q.pop();
					auto t = cur[u] & nvis;
					for (int v = t._Find_first(); v < idC; v = t._Find_next(v)) {
						q.push(v), nvis.reset(v);
					}
				}
				puts(nvis[id[bel[ope[i].y]]] ? "NO" : "YES");
			}
		}
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 11800kb

input:

5 6 7
1 2
1 3
2 4
3 4
3 5
4 5
2 1 5
2 2 3
1 3
1 4
2 1 4
1 3
2 1 5

output:

YES
NO
NO
YES

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 1236ms
memory: 18224kb

input:

50000 100000 100000
36671 44121
25592 44321
13226 46463
13060 25694
14021 20087
22881 38333
34655 47774
22868 26462
31154 48710
27491 32365
5874 47497
17622 28600
1886 14193
22315 23656
14973 22704
1335 25384
22612 34915
2852 48213
23334 25519
24342 28784
6238 36125
14598 39494
33069 34250
2123 3059...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

wrong answer 3413th lines differ - expected: 'YES', found: 'NO'