Submission #54367

# Submission time Handle Problem Language Result Execution time Memory
54367 2018-07-03T09:05:49 Z 노영훈(#1472) Sails (IOI07_sails) C++11
5 / 100
148 ms 2288 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9, HMX=100000;

int n;
pii P[MX];

ll tree[MX];
void upt(int pos, int val){
    for(; pos>0; pos-=pos&(-pos))
        tree[pos]+=val;
}
void upt(int l, int r, int val){
    if(r<l) return;
    // cout<<l<<' '<<r<<'\n';
    upt(r, val); upt(l-1, -val);
}
int val(int pos){
    ll res=0;
    for(; 0<pos && pos<=HMX; pos+=pos&(-pos))
        res+=tree[pos];
    return res;
}

ll ans;
bool solve(int x){
    for(int i=1; i<=HMX; i++) tree[i]=0;
    int hi=HMX;
    for(int i=1; i<=n; i++){
        int h,a; tie(h,a)=P[i];
        hi=min(hi, h);
        while(hi>0 && val(hi)>=x) hi--;
        int lo=hi-a+1;
        if(lo<=0) return false;
        upt(lo, hi, 1);
    }
    ans=0;
    for(int i=1; i<=HMX; i++){
        ll x=val(i);
        ans+=x*(x-1)/2;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++){
        int h, a; cin>>h>>a;
        P[i]={h,a};
    }
    sort(P+1, P+n+1, greater<pii>());
    int s=0, e=n;
    while(s<e){
        int m=(s+e)/2;
        if(solve(m)) e=m;
        else s=m+1;
    }
    solve(s);
    // cout<<s<<'\n';
    // for(int i=1; i<=10; i++) cout<<val(i)<<' ';
    // cout<<'\n';
    cout<<ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1144 KB Output is correct
2 Correct 12 ms 1252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1252 KB Output is correct
2 Incorrect 7 ms 1260 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1260 KB Output is correct
2 Incorrect 7 ms 1288 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 1448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 1644 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 1792 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 138 ms 2028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 131 ms 2112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 148 ms 2288 KB Output isn't correct
2 Halted 0 ms 0 KB -