Submission #291164

# Submission time Handle Problem Language Result Execution time Memory
291164 2020-09-04T19:47:19 Z couplefire Sails (IOI07_sails) C++17
90 / 100
93 ms 7032 KB
#include <bits/stdc++.h>
using namespace std;

int prefix[100005] = {0};
set<int> nextPos;
set<int> prevPos;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // freopen("a.in", "r", stdin);
    int n; cin >> n;
    pair<int, int> arr[n];
    for(int i = 0; i<n; i++) cin >> arr[i].first >> arr[i].second;
    sort(arr, arr+n);
    int cur = 100005;
    nextPos.insert(cur);
    prevPos.insert(-cur);
    for(auto p : arr){
        int height = p.first, num = p.second;
        cur = 100005-height;
        prefix[cur]++;
        nextPos.insert(cur);
        prevPos.insert(-cur);
        if(cur+num == 100005) continue;
        prefix[cur+num]--;
        if(prefix[cur+num] == 0) nextPos.erase(cur+num), prevPos.erase(-cur-num);
        if(prefix[cur+num] == -1){
            int npos = *nextPos.lower_bound(cur+num);
            int ppos = -*prevPos.lower_bound(-cur-num);
            prefix[npos]--;
            if(prefix[npos] == 0) nextPos.erase(npos), prevPos.erase(-npos);
            prefix[ppos]--;
            if(prefix[ppos] == 0) nextPos.erase(ppos), prevPos.erase(-ppos);
            prefix[cur+num] = 0;
            prefix[npos+ppos-cur-num] = 1;
            nextPos.insert(npos+ppos-cur-num);
            prevPos.insert(-npos-ppos+cur+num);
        }
        // cout << height << " " << num << endl;
        // int cnum = 0;
        // for(int i = cur; i<100005; i++){
        //     cnum += prefix[i];
        //     cout << cnum << " ";
        // }
        // cout << endl;
    }
    long long ans = 0;
    int cnum = 0;
    for(int i = cur; i<100005; i++){
        cnum += prefix[i];
        ans += cnum*(cnum-1)/2;
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 21 ms 1056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 2400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 2608 KB Output is correct
2 Correct 60 ms 3768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 7032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 93 ms 4088 KB Output is correct
2 Correct 43 ms 2284 KB Output is correct