0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 21:25:24 +00:00

#1426. 【2022.5.21 联考】空

https://sjzezoj.com/submission/53072
This commit is contained in:
Baoshuo Ren 2022-05-22 20:47:37 +08:00
parent 728d3da95e
commit 74ab0166cc
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

71
S2OJ/1426/1426.cpp Normal file
View File

@ -0,0 +1,71 @@
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e5 + 5;
int n, ans;
std::pair<int, int> lines[N];
// 包含
std::priority_queue<
std::pair<int, int>,
std::vector<std::pair<int, int>>,
auto(*)(std::pair<int, int>, std::pair<int, int>)->bool>
q1([](std::pair<int, int> a, std::pair<int, int> b) -> bool {
return a.second - a.first < b.second - b.first;
});
// 相交
std::priority_queue<
std::pair<int, int>,
std::vector<std::pair<int, int>>,
auto(*)(std::pair<int, int>, std::pair<int, int>)->bool>
q2([](std::pair<int, int> a, std::pair<int, int> b) -> bool {
return a.first + a.second > b.first + b.second;
});
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> lines[i].first >> lines[i].second;
}
std::sort(lines + 1, lines + 1 + n);
q1.push(lines[1]);
q2.push(lines[1]);
for (int i = 2; i <= n; i++) {
while (!q1.empty() && lines[i].second >= q1.top().second) q1.pop(); // 剔除已经相交的线段
while (!q2.empty() && lines[i].first >= q2.top().second) q2.pop(); // 剔除已经相离的线段
if (!q1.empty()) {
auto p = q1.top(),
q = lines[i];
ans = std::max(ans, (p.second - p.first) - (q.second - q.first));
}
if (!q2.empty()) {
auto p = q2.top(),
q = lines[i];
ans = std::max(ans, (q.second - p.second) + (q.first - p.first));
}
q1.push(lines[i]);
q2.push(lines[i]);
}
cout << ans << endl;
return 0;
}