답안 #1017236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017236 2024-07-09T06:51:18 Z dosts Sails (IOI07_sails) C++17
100 / 100
130 ms 8796 KB
//Dost SEFEROĞLU
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " << 
#define vi vector<int>
#define all(xx) xx.begin(),xx.end()
const int N = 1e6+1,inf = 2e9,B = 23,MOD = 30013,LIM = 1e9;    
 
struct ST {
    vi t,lazy;

    ST(int nn) {
        t.assign(4*nn+1,0);
        lazy.assign(4*nn+1,0);
    }
    void push(int node,bool leaf) {
        t[node]+=lazy[node];
        if (!leaf) {
            lazy[2*node]+=lazy[node];
            lazy[2*node+1]+=lazy[node];
        }
        lazy[node] = 0;
    }
    void update(int node,int l,int r,int L,int R,int v) {
        push(node,l==r);
        if (l > R || r < L) return;
        if (l >= L && r <= R) {
            lazy[node] += v;
            push(node,l==r);
            return;
        }
        int m = (l+r) >> 1;
        update(2*node,l,m,L,R,v),update(2*node+1,m+1,r,L,R,v);
        t[node] = min(t[2*node],t[2*node+1]);
    }
    int query(int node,int l,int r,int p) {
        push(node,l==r);
        if (l == r) return t[node];
        int m = (l+r) >> 1;
        if (p <= m) return query(2*node,l,m,p);
        else return query(2*node+1,m+1,r,p);
    }
    int walk(int node,int l,int r,int x) {
        push(node,l==r);
        if (t[node] >= x) return -1;
        if (l == r) return l;
        int m = (l+r) >> 1;
        int pp = walk(2*node,l,m,x);
        if (pp != -1) return pp;
        return walk(2*node+1,m+1,r,x);
    }
    int walk2(int node,int l,int r,int x) {
        push(node,l==r);
        if (t[node] > x) return -1;
        if (l == r) return l;
        int m = (l+r) >> 1;
        int pp = walk2(2*node,l,m,x);
        if (pp != -1) return pp;
        return walk2(2*node+1,m+1,r,x);
    }
    int worth(int node,int l,int r) {
        push(node,l==r);
        if (l == r) return t[node]*(t[node]-1)/2;
        int m = (l+r) >> 1;
        return worth(2*node,l,m)+worth(2*node+1,m+1,r);
    }
};


void solve() {
    int n;
    cin >> n;
    vector<pii> poles(n+1);
    for (int i=1;i<=n;i++) cin >> poles[i].ff >> poles[i].ss;
    sort(poles.begin()+1,poles.end());
    ST st(100000);
    int curheight = 1;
    for (int i=1;i<=n;i++) {
        curheight = poles[i].ff;
        int x = poles[i].ss;
        int big = st.query(1,1,100000,curheight-x+1);
        int smbig = st.walk(1,1,100000,big); //<big olan ilk yer 
        int firstbig = st.walk2(1,1,100000,big); // =big olan ilk yer
        if (smbig != -1 && smbig <= curheight) st.update(1,1,100000,smbig,curheight,1);
        int rem = x-(curheight-smbig+1);
        if (smbig == -1 || smbig > curheight) rem = x;
        st.update(1,1,100000,firstbig,firstbig+rem-1,1);
    }
    cout << st.worth(1,1,100000) << '\n';
}  
 
                
                            
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6748 KB Output is correct
2 Correct 4 ms 6700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6748 KB Output is correct
2 Correct 35 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 7000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 7780 KB Output is correct
2 Correct 81 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 8028 KB Output is correct
2 Correct 50 ms 8724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 8284 KB Output is correct
2 Correct 82 ms 8284 KB Output is correct