QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#216340#6439. Cloud Retainer's Gameveg#WA 0ms5900kbC++141.8kb2023-10-15 17:37:242023-10-15 17:37:25

Judging History

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

  • [2023-10-15 17:37:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5900kb
  • [2023-10-15 17:37:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
struct AAA {
	int x, y, t;
} a[200005];
int dp[200005][2];
map<int, int> M1, M2;
int ncnt, H;
struct Node {
	int ls, rs, mx;
} t[7000005];
void add(int &p, int l, int r, int x, int y) {
	if (!p) {
		p = ++ncnt;
		t[p].ls = t[p].rs = t[p].mx = 0;
	}
	t[p].mx = max(t[p].mx, y);
	if (l == r) return;
	int mid = l + (r - l) / 2;
	if (x <= mid) add(t[p].ls, l, mid, x, y);
	else add(t[p].rs, mid + 1, r, x, y);
}
int ask(int p, int l, int r, long long x) {
	if (!p || l > x) return -1e9;
	if (r <= x) return t[p].mx;
	int mid = l + (r - l) / 2;
	return max(ask(t[p].ls, l, mid, x), ask(t[p].rs, mid + 1, r, x));
}
void ins(int i) {
	add(M1[(a[i].x - a[i].y + H) % H], -1e9, 1e9, a[i].x - a[i].y, dp[i][0]);
	add(M2[(a[i].x + a[i].y) % H], 0, 2e9, a[i].x + a[i].y, dp[i][1]);
}
int main() {
	int T;
	cin >> T;
	while (T--) {
		M1.clear();
		M2.clear();
		ncnt = 0;
		int n, m;
		scanf("%d", &H);
H+=H;
		scanf("%d", &n);
		for (int i = 1; i <= n; ++i) {
			int x, y;
			scanf("%d%d", &x, &y);
			a[i] = (AAA){x, y, 0};
		}
		scanf("%d", &m);
		for (int i = 1; i <= m; ++i) {
			int x, y;
			scanf("%d%d", &x, &y);
			a[i + n] = (AAA){x, y, 1};
		}
		sort(a + 1, a + n + m + 1, [](const AAA &a, const AAA &b) { return a.x < b.x; });
		ins(0);
		int ans = 0;
		for (int i = 1; i <= n + m; ++i) {
			dp[i][1] = a[i].t + max(ask(M1[(a[i].x + a[i].y) % H], -1e9, 1e9, 1ll * a[i].x + a[i].y - H),
							ask(M2[(a[i].x + a[i].y) % H], 0, 2e9, a[i].x + a[i].y - H));
			dp[i][0] = a[i].t + max(ask(M1[(a[i].x - a[i].y + H) % H], -1e9, 1e9, 1ll * a[i].x - a[i].y - H),
							ask(M2[(a[i].x - a[i].y + H) % H], 0, 2e9, a[i].x - a[i].y));
			ans = max(ans, dp[i][1]);
			ans = max(ans, dp[i][0]);
			if (!a[i].t) swap(dp[i][1], dp[i][0]);
			ins(i);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5900kb

input:

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

output:

2
3

result:

wrong answer 1st numbers differ - expected: '3', found: '2'