QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69571#2442. Welcome Partyhe_ren_shi_lyp#AC ✓362ms10428kbC++231.2kb2022-12-28 18:34:452022-12-28 18:34:48

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-28 18:34:48]
  • Judged
  • Verdict: AC
  • Time: 362ms
  • Memory: 10428kb
  • [2022-12-28 18:34:45]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false), cin.tie(0);
	int T;
	for(cin >> T; T; T --) {
		int n;
		cin >> n;
		vector<pair<i64, i64>> a(n);
		for(auto &[x, y] : a) cin >> x >> y;
		sort(a.begin(), a.end());
		set<i64> s;
		vector<i64> mx(n);
		mx.back() = a.back().second;
		for(int i = n - 2; i >= 0; i --) mx[i] = max(mx[i + 1], a[i].second);
		i64 ans = 8e18;
		for(int i = 0; i < n - 1; i ++) {
			i64 cur = a[i].first;
			i64 val = mx[i + 1];
			if(val < cur) {
				auto it = s.upper_bound(cur);
				ans = min(ans, abs(cur - val));
				if(it != s.begin()) {
					it --;
					val = max(val, *it);
					ans = min(ans, abs(cur - val));
					it ++;
				} 
				if(it != s.end()) {
					val = max(val, *it);
					ans = min(ans, abs(cur - val));
				}
			} 
			ans = min(ans, abs(cur - val));
			s.insert(a[i].second);
		}
		{
			i64 cur = a[n - 1].first;
			auto it = s.upper_bound(cur);
			if(it != s.begin()) {
				it --;
				ans = min(ans, abs(cur - *it));
				it ++;
			} 
			if(it != s.end()) {
				ans = min(ans, abs(cur - *it));
			}
		}
		cout << ans << '\n';
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 362ms
memory: 10428kb

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
10974087366700578
21076180420813408
183538167814754058
46751451188711820
365292306661444331
23639646046527434
40476687889457528
270663364266559542
139940820548070767
21494649603533736
100200...

result:

ok 66 lines