Submission #1361124

#TimeUsernameProblemLanguageResultExecution timeMemory
1361124tarjanmiciSails (IOI07_sails)C++20
70 / 100
1096 ms1504 KiB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
    int n, high=0;
    cin >> n;
    vector<pair<int, int>> mast(n);
    vector<int> cnt(100001);
    cnt[0] = 100002;
    for (int i = 0; i < n; i++) {
        cin >> mast[i].first >> mast[i].second;
        high = max(high, mast[i].first);
    }
    sort(mast.begin(), mast.end());
    for (int i = 0; i < n; i++) {
        int h = mast[i].first, k = mast[i].second;
        for (int j = h; j > h - k; j--) {
            cnt[j]++;
        }
        if (cnt[h - k] < cnt[h - k + 1]) {
            int j = h - k, l = h - k + 1;
            while (cnt[l] == cnt[h - k + 1])l++;
            while (cnt[j] == cnt[h - k]) j--;
            for (int m = j+1; m - j <= l - (h - k + 1); m++) cnt[m]++;
            for (int m = h - k + 1; m < l; m++)cnt[m]--;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= high; i++) {
        ans += ll(cnt[i]) * ll(cnt[i] - 1) / 2;
    }
    cout << ans;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...