답안 #1058862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058862 2024-08-14T14:36:05 Z vjudge1 Bigger segments (IZhO19_segments) C++17
13 / 100
106 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;
ll a[N];

//Dynamic Segtree
const ll L = 0,R = 1e15;
struct node{
    int l,r; 
    ll val;
    node(){l = -1,r = -1,val = 0;}
};
vector<node>tr;
void init(){
    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;
        for(int i = 1;i <= n;++i){
            cin>>a[i];
            a[i] += a[i - 1];
        }
        /*
            dp[i] la max group tai vi tri thu i 
            opt[i] la min sum cua nhom chua vi tri thu i 
            dp[i] = dp[j - 1] + 1 voi j = vi tri gan nhat ma opt[j - 1] <= a[i] - a[j - 1] 
                                                            => opt[j - 1] + a[j - 1] <= a[i]
        */
        init();
        vector<ll>dp(n + 1),opt(n + 1);
        for(int i = 1;i <= n;++i){
            int j = get(0,a[i]);
            dp[i] = dp[j] + 1; 
            opt[i] = a[i] - a[j]; 
            update(opt[i] + a[i],i);
        }
        cout<<dp[n]<<endl;
    };
    int t = 1; // cin>>t;
    while (t--) solver();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Runtime error 106 ms 262144 KB Execution killed with signal 9
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Runtime error 106 ms 262144 KB Execution killed with signal 9
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Runtime error 106 ms 262144 KB Execution killed with signal 9
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Runtime error 106 ms 262144 KB Execution killed with signal 9
18 Halted 0 ms 0 KB -