Submission #54363

# Submission time Handle Problem Language Result Execution time Memory
54363 2018-07-03T08:50:22 Z 노영훈(#1472) Sails (IOI07_sails) C++11
5 / 100
36 ms 2024 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){
    int res=0;
    for(; 0<pos && pos<=HMX; pos+=pos&(-pos))
        res+=tree[pos];
    return res;
}

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>());
    for(int i=1; i<=n; i++){
        // cout<<i<<' '<<P[i].first<<' '<<P[i].second<<'\n';
        int up=P[i].first;
        int dn=up-P[i].second+1;
        int r=i+1;
        while(r<=n && dn<=P[r].first && dn>1){
            int h, a; tie(h,a)=P[r];
            int x=min(a, dn-1);
            a-=x;
            dn=dn-x;
            P[r]={h,a};
            r++;
        }
        // cout<<up<<' '<<dn<<'\n';
        upt(dn, up, 1);
    }
    ll ans=0;
    for(int i=1; i<=HMX; i++){
        ll x=val(i);
        // cout<<x<<' ';
        ans+=x*(x-1)/2;
    }
    cout<<ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 5 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 1084 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 1384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 1384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 2020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -