This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
using ll = long long;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
vector<array<int, 2>> A(N);
for(auto& x : A) {
cin >> x[0] >> x[1];
}
set<int> S; for(int i = 0; i < N; i++) S.insert(i);
vector<int> IDX; for(int i = 0; i < N; i++) IDX.push_back(i);
for(int t = 0; t < 2; t++) {
sort(begin(IDX), end(IDX), [&](int x, int y) {
if (A[x] == A[y]) return x < y;
return A[x] < A[y];
});
vector<int> stk = {-1};
for(auto i : IDX) {
while(stk.back() != -1 && (A[stk.back()][1] - A[stk.back()][0]) <= (A[i][1] - A[i][0])) {
stk.pop_back();
}
stk.push_back(i);
}
set<int> NS;
for(auto x : stk) {
// cout << x << " ";
if (S.count(x)) NS.insert(x);
}
// cout << nl;
S.swap(NS);
for(auto& x : A) x[0] = -x[0];
}
cout << size(S) << nl;
return 0;
}
/*
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |