제출 #781872

#제출 시각아이디문제언어결과실행 시간메모리
781872borisAngelovAdvertisement 2 (JOI23_ho_t2)C++17
100 / 100
671 ms56940 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 500005; int n; struct resident { int e; int x; }; resident a[maxn]; bool cmp(resident p, resident q) { return p.e > q.e; } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i].x >> a[i].e; } sort(a + 1, a + n + 1, cmp); set<pair<int, int>> smaller; set<pair<int, int>> bigger; int ans = 0; for (int i = 1; i <= n; ++i) { bool covered = false; auto it = smaller.lower_bound(make_pair(a[i].e - a[i].x, 0)); if (it != smaller.end() && it->second >= a[i].x) { covered = true; } auto it2 = bigger.lower_bound(make_pair(a[i].e + a[i].x, 0)); if (it2 != bigger.end() && it2->second <= a[i].x) { covered = true; } if (covered == false) { ++ans; smaller.insert(make_pair(a[i].e - a[i].x, a[i].x)); bigger.insert(make_pair(a[i].e + a[i].x, a[i].x)); } } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...