QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#619281#2442. Welcome Partyuntitledtwo#WA 402ms13196kbC++171.7kb2024-10-07 13:44:182024-10-07 13:44:19

Judging History

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

  • [2024-10-07 13:44:19]
  • 评测
  • 测评结果:WA
  • 用时:402ms
  • 内存:13196kb
  • [2024-10-07 13:44:18]
  • 提交

answer

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

const int MAXN = 200005;
typedef long long ll;
typedef pair<ll, ll> PR;
#define fi first
#define se second
#define PB push_back
#define MP make_pair

pair<ll, ll> a[MAXN];
set<ll> Set;
ll mx[MAXN];

signed main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
#endif
	int Case;
	scanf("%d", &Case);
	while (Case --) {
		int n;
		scanf("%d", &n);
		for (int i = 1; i <= n ; ++ i) scanf("%lld%lld", &a[i].fi, &a[i].se);
		sort(a + 1, a + n + 1, [&](PR a, PR b){ return (a.fi > b.fi) || (a.fi == b.fi && a.se < b.se); });
		ll ans = (ll)1e19;
		Set.clear();
		for (int i = 1; i <= n ; ++ i) mx[i] = max(mx[i - 1], a[i].se);
		for (int i = n; i >= 1 ; -- i) {
			ll t = -(ll)1e19;
			auto nxt = Set.lower_bound(a[i].fi), pre = nxt;
			if (pre != Set.begin()) {
				-- pre;
				if (abs(t - a[i].fi) > abs(*pre - a[i].fi)) t = *pre;
			}
			if (nxt != Set.end()) {
				if (abs(t - a[i].fi) > abs(*nxt - a[i].fi)) t = *nxt;
			}
			ans = min(ans, abs(max(mx[i - 1], t) - a[i].fi));
			Set.insert(a[i].se);
		}

		Set.clear();
		sort(a + 1, a + n + 1, [&](PR a, PR b){ return (a.fi > b.fi) || (a.fi == b.fi && a.se > b.se); });
		for (int i = 1; i <= n ; ++ i) mx[i] = max(mx[i - 1], a[i].se);
		for (int i = n; i >= 1 ; -- i) {
			ll t = -(ll)1e19;
			auto nxt = Set.lower_bound(a[i].fi), pre = nxt;
			if (pre != Set.begin()) {
				-- pre;
				if (abs(t - a[i].fi) > abs(*pre - a[i].fi)) t = *pre;
			}
			if (nxt != Set.end()) {
				if (abs(t - a[i].fi) > abs(*nxt - a[i].fi)) t = *nxt;
			}
			ans = min(ans, abs(max(mx[i - 1], t) - a[i].fi));
			Set.insert(a[i].se);
		}
		printf("%lld\n", ans);
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 402ms
memory: 13196kb

input:

66
5
27 46
89 13
55 8
71 86
22 35
3
3 5
4 7
6 2
2
0 1000000000
1000000000 0
2
1000000000 0
0 1000000000
2
1000000000 0
1000000000 0
2
0 1000000000
0 1000000000
2
1000000000 1000000000
0 0
2
0 0
0 0
2
1000000000 1000000000
1000000000 1000000000
3
90 30
90 50
90 85
3
0 0
0 2
0 5
3
20 30
20 50
20 70
3
...

output:

3
1
0
0
1000000000
1000000000
1000000000
0
0
5
0
10
5
10
3
0
10
5
0
5
0
10
5
10
3
0
10
5
0
146595730144168239
13421384895232913
21076180420813408
183538167814754058
46751451188711820
365292306661444331
23639646046527434
40476687889457528
270663364266559542
139940820548070767
48500389324554138
100200...

result:

wrong answer 31st lines differ - expected: '10974087366700578', found: '13421384895232913'