QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#204345#6308. MagiczhouyuhangWA 12ms10800kbC++142.3kb2023-10-07 10:20:452023-10-07 10:20:45

Judging History

This is the latest submission verdict.

  • [2023-10-07 10:20:45]
  • Judged
  • Verdict: WA
  • Time: 12ms
  • Memory: 10800kb
  • [2023-10-07 10:20:45]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 5e3 + 10;

int n;
int a[N << 1];

struct edge {
	int to, flow;
	int nxt;
} e[N << 7];

int head[N << 5], cur[N << 5], id = 0;
void addE(int u, int v, int f) {
	e[id].to = v, e[id].flow = f;
	e[id].nxt = head[u], head[u] = id++;
}
void add(int u, int v, int f) {
	addE(u, v, f);
	addE(v, u, 0);
}

int S, T; 

int dis[N << 5];
queue<int> q; 
bool bfs() {
	memset(dis, -1, sizeof dis);
	q.push(S); dis[S] = 0;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int i = head[u]; ~i; i = e[i].nxt) if (e[i].flow) {
			int v = e[i].to;
			if (dis[v] == -1) {
				dis[v] = dis[u] + 1;
				q.push(v);
			}
		}
	}
	return ~dis[T];
}
int dfs(int u, int a) {
	if (u == T || !a) return a;
	int flow = 0, f;
	for (int i = cur[u]; ~i; i = e[i].nxt) {
		cur[u] = i;
		int v = e[i].to;
		if (dis[v] == dis[u] + 1 && (f = dfs(v, min(a, e[i].flow))) > 0) {
			e[i].flow -= f, e[i ^ 1].flow += f;
			a -= f, flow += f;
			if (!a) break;
		}
	}
	return flow;
}
int Dinic() {
	int ans = 0;
	while (bfs()) {
		memcpy(cur, head, sizeof cur);
		ans += dfs(S, 0x3f3f3f3f);
	}
	return ans;
}

int root, tNode;
int lc[N << 4], rc[N << 4];
void modify(int &p, int sl, int sr, int idx) {
	if (sl == sr) {
		if (!a[sl]) p = sl;
		return;
	}
	++tNode;
	lc[tNode] = lc[p], rc[tNode] = rc[p];
	p = tNode;
	int mid = (sl + sr) >> 1;
	if (idx <= mid) modify(lc[p], sl, mid, idx);
	else modify(rc[p], mid + 1, sr, idx);
	if (lc[p]) add(p, lc[p], 1);
	if (rc[p]) add(p, rc[p], 1);
}
void query(int p, int sl, int sr, int ql, int qr, int u) {
	if (!p) return;
	if (ql <= sl && sr <= qr) return add(u, p, 1);
	int mid = (sl + sr) >> 1;
	if (ql <= mid) query(lc[p], sl, mid, ql, qr, u);
	if (mid < qr) query(rc[p], mid + 1, sr, ql, qr, u);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int l, r;
		cin >> l >> r;
		a[l] = r;
	}
	
	memset(head, -1, sizeof head); tNode = (n << 1);
	for (int i = 1; i <= (n << 1); ++i) if (a[i]) {
		query(root, 1, (n << 1), i, a[i], i);
		modify(root, 1, (n << 1), a[i]);
	}
	S = tNode + 1, T = tNode + 2;
	for (int i = 1; i <= (n << 1); ++i) {
		if (a[i]) add(S, i, 1);
		else add(i, T, 1);
	}
	
	cout << (n << 1) - Dinic() << endl;

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5996kb

input:

5
2 3
6 7
1 9
5 10
4 8

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 5ms
memory: 8724kb

input:

5000
7985 7987
42 46
1591 1593
407 410
6305 6306
1456 1457
5874 5875
7135 7137
7041 7046
6813 6815
8868 8871
665 666
4055 4056
9789 9796
7067 7068
4745 4746
5167 5171
1735 1737
2125 2128
1444 1447
1348 1352
6087 6090
1381 1384
1600 1601
5187 5190
2801 2802
8449 8450
9376 9377
4021 4024
2674 2676
490...

output:

8134

result:

ok 1 number(s): "8134"

Test #3:

score: -100
Wrong Answer
time: 12ms
memory: 10800kb

input:

5000
3171 3172
4062 4064
4647 4651
3670 3673
7112 7114
9714 9717
3781 3789
8422 8426
457 460
5450 5454
7113 7122
6313 6320
9969 9973
828 832
6878 6892
4476 4483
892 903
251 259
6304 6315
130 134
9206 9215
2679 2686
9090 9091
8222 8228
9374 9375
2985 2989
3397 3401
4916 4918
6819 6821
883 889
2516 25...

output:

7073

result:

wrong answer 1st numbers differ - expected: '7047', found: '7073'