Submission #1005387

# Submission time Handle Problem Language Result Execution time Memory
1005387 2024-06-22T11:47:42 Z bachhoangxuan Sails (IOI07_sails) C++17
100 / 100
39 ms 4700 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
set<int> s;
int cnt[maxn];

void add(int x,int val){
    cnt[x]+=val;
    if(!cnt[x]) s.erase(x);
    else s.insert(x);
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n;cin >> n;
    vector<pair<int,int>> p(n);
    for(int i=0;i<n;i++) cin >> p[i].first >> p[i].second;
    sort(p.begin(),p.end());
    int mx=0;
    for(auto [h,k]:p){
        mx=max(mx,h);
        auto it=s.upper_bound(h-k+1);
        int l=1,r=(it==s.end()?h:*it-1);
        if(it!=s.begin()){it--;l=*it;}
        if(r<h) add(r+1,1),add(h+1,-1),k-=(h-r);
        if(k) add(l,1),add(l+k,-1);
    }
    long long total=0;
    for(int i=1;i<=mx;i++){
        cnt[i]+=cnt[i-1];
        total+=1LL*cnt[i]*(cnt[i]-1)/2;
    }
    cout << total << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 8 ms 952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2396 KB Output is correct
2 Correct 23 ms 2972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 4700 KB Output is correct
2 Correct 17 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 3272 KB Output is correct
2 Correct 16 ms 2396 KB Output is correct