제출 #944512

#제출 시각아이디문제언어결과실행 시간메모리
944512vladiliusAdvertisement 2 (JOI23_ho_t2)C++17
59 / 100
20 ms4952 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; struct node{ int x, e; }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; vector<node> t(n + 1); for (int i = 1; i <= n; i++){ cin>>t[i].x>>t[i].e; } auto cmp = [&](node a, node b){ return (a.e >= b.e); }; sort(t.begin() + 1, t.end(), cmp); vector<int> d(n + 1), s(n + 1); for (int i = 1; i <= n; i++){ d[i] = t[i].e - t[i].x; s[i] = t[i].e + t[i].x; } set<pii> s1, s2; for (int i = 1; i <= n; i++){ s1.insert({d[i], i}); s2.insert({s[i], i}); } int out = 0; vector<bool> used(n + 1); for (int i = 1; i <= n; i++){ if (used[i]) continue; used[i] = true; // xj <= xi and d[j] <= d[i] // xj > xi and s[j] <= s[i] auto it = s1.begin(); vector<int> rem; while (it != s1.end()){ auto [a, j] = *it; if (a > d[i]) break; if (t[j].x > t[i].x){ it++; continue; } rem.push_back(j); it++; } it = s2.begin(); while (it != s2.end()){ auto [a, j] = *it; if (a > s[i]) break; if (used[j] || t[j].x < t[i].x){ it++; continue; } rem.push_back(j); it++; } for (int j: rem){ used[j] = true; s1.erase({d[j], j}); s2.erase({s[j], j}); } out++; } cout<<out<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...