Submission #1058922

# Submission time Handle Problem Language Result Execution time Memory
1058922 2024-08-14T15:07:34 Z vjudge1 Bigger segments (IZhO19_segments) C++17
0 / 100
126 ms 262144 KB
#include <bits/stdc++.h>
#ifdef LOCAL
    #include "/home/trcmai/code/tools.h"
    #define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
    #define debug(x...)
#endif
using namespace std;
#define all(a) a.begin(), a.end()
#define ll long long
#define endl '\n'
const int N = 1e6 + 6, LOG = 27, MOD = 1e9 + 7;
const ll INF = 1e18;
int n;

//Dynamic Segtree
struct segtree{
    const ll L = 0,R = INF;
    struct node{
        int l,r; ll val;
        node(){l = -1,r = -1,val = 0;}
    };
    vector<node>tr;
    segtree(){ tr.clear(); tr.emplace_back(); }
    void extend(int idx){
        if(tr[idx].l == -1){ tr[idx].l = tr.size(); tr.emplace_back(); }
        if(tr[idx].r == -1){ tr[idx].r = tr.size(); tr.emplace_back(); }
    }
    void update(int i,ll l,ll r,ll pos,int val){
        if(l == r){ tr[i].val = val; return; }
        int m = (r+l) >> 1; extend(i);
        if(pos <= m) update(tr[i].l,l,m,pos,val);
        else update(tr[i].r,m + 1,r,pos,val);
        tr[i].val = max(tr[tr[i].l].val,tr[tr[i].r].val);
    }
    int get(int i,ll l,ll r,ll ql,ll qr){
        if(l > qr || r < ql) return 0;
        if(ql <= l && r <= qr) return tr[i].val;
        int m = (r+l) >> 1,res = 0; 
        if(tr[i].l != -1) res = max(res,get(tr[i].l,l,m,ql,qr));
        if(tr[i].r != -1) res = max(res,get(tr[i].r,m+1,r,ql,qr));
        return res;
    }
    void update(ll pos,int val){ update(0,L,R,pos,val);}
    ll get(ll l,ll r){ return get(0,L,R,l,r);}
};
signed main() {
    cin.tie(0)->sync_with_stdio(0);
    auto solver=[&](){
        cin>>n; 
        vector<ll>a(n + 1),dp(n + 1),opt(n + 1);
        for(int i = 1;i <= n;++i){
            cin>>a[i];
            a[i] += a[i - 1];
        }
        segtree st;
        for(int i = 1;i <= n;++i){
            int j = st.get(0,a[i]);
            dp[i] = dp[j] + 1; 
            opt[i] = a[i] - a[j]; 
            st.update(opt[i] + a[i],i);
        }
        cout<<dp[n]<<endl;
    };
    int t = 1; // cin>>t;
    while (t--) solver();
}
# Verdict Execution time Memory Grader output
1 Runtime error 126 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 126 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 126 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 126 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 126 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -