Submission #768459

#TimeUsernameProblemLanguageResultExecution timeMemory
768459green_gold_dogAdvertisement 2 (JOI23_ho_t2)C++17
10 / 100
677 ms85432 KiB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

template<typename T>
bool assign_min(T& a, T b) {
        if (a > b) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
bool assign_max(T& a, T b) {
        if (a < b) {
                a = b;
                return true;
        }
        return false;
}

struct cmp {
        constexpr bool operator() (const pair<ll, ll>& p1, const pair<ll, ll>& p2) const {
                return (p1.second == p2.second ? p1.first < p2.first : p1.second > p2.second);
        }
};

struct sum_cmp {
        constexpr bool operator() (const pair<ll, ll>& p1, const pair<ll, ll>& p2) const {
                return (p1.first + p1.second == p2.first + p2.second ? p1.first < p2.first : p1.first + p1.second < p2.first + p2.second);
        }
};

struct sub_cmp {
        constexpr bool operator() (const pair<ll, ll>& p1, const pair<ll, ll>& p2) const {
                return (p1.first - p1.second == p2.first - p2.second ? p1.first < p2.first : p1.first - p1.second > p2.first - p2.second);
        }
};

void solve() {
        ll n;
        cin >> n;
        set<pair<ll, ll>, cmp> s1;
        set<pair<ll, ll>, sum_cmp> s2;
        set<pair<ll, ll>, sub_cmp> s3;
        for (ll i = 0; i < n; i++) {
                ll x, y;
                cin >> x >> y;
                s1.emplace(x, y);
                s2.emplace(x, y);
                s3.emplace(x, y);
        }
        ll ans = 0;
        while (!s1.empty()) {
                ans++;
                auto[x, y] = *s1.begin();
                s3.erase(*s1.begin());
                s2.erase(*s1.begin());
                s1.erase(s1.begin());
                while (!s2.empty()) {
                        auto[nx, ny] = *s2.begin();
                        if (abs(x - nx) <= y - ny) {
                                s3.erase(*s2.begin());
                                s1.erase(*s2.begin());
                                s2.erase(s2.begin());
                        } else {
                                break;
                        }
                }
                while (!s3.empty()) {
                        auto[nx, ny] = *s3.begin();
                        if (abs(x - nx) <= y - ny) {
                                s1.erase(*s3.begin());
                                s2.erase(*s3.begin());
                                s3.erase(s3.begin());
                        } else {
                                break;
                        }
                }
        }
        cout << ans << '\n';
}

int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...