Submission #957147

# Submission time Handle Problem Language Result Execution time Memory
957147 2024-04-03T05:14:31 Z Requiem Bigger segments (IZhO19_segments) C++17
73 / 100
39 ms 4836 KB
#include <bits/stdc++.h>
#define int long long
#define ii pair<int, int>
#define iii pair<int,ii>
#define vii vector<ii>
#define fi first
#define se second
#define endl '\n'
#define show(T) {for (auto x:T) cout<<x<<' ';cout<<endl;}
using namespace std;
const double eps = 0.0000001;
const int mod = 1e9+7;
const int N = 100005;
const int MATRIX_SIZE = 64;
int n,st[4*N],mcd[N],sum[N],dp[N];
void up(int id,int l,int r,int pos,int val){
    if (l>pos||r<pos) return;
    if (l==r){
        st[id]=val;
        return;
    }
    int mid=(l+r)>>1;
    up(id<<1,l,mid,pos,val);
    up(id<<1|1,mid+1,r,pos,val);
    st[id]=min(st[id<<1],st[id<<1|1]);
}
int get(int id,int l,int r,int ct,int cp,int val){
    if (l>cp||r<ct||st[id]>val) return 1e18;
    if (l==r){
        if (st[id]<=val) return l;
        return 1e18;
    }
    int mid=(l+r)>>1;
    int tam=get(id<<1|1,mid+1,r,ct,cp,val);
    if (tam==1e18)
        tam=get(id<<1,l,mid,ct,cp,val);
    return tam;
}
void solve(){
    cin>>n;
    for (int i=1,tam,pos;i<=n;++i){
        cin>>tam;
        mcd[i]=mcd[i-1]+tam;
        pos=get(1,1,n,1,i-1,mcd[i]);
        if (pos==1e18) pos=0;
        sum[i]=mcd[i]-mcd[pos];
        dp[i]=dp[pos]+1;
        // cout<<i<<' '<<pos<<endl;
        up(1,1,n,i,sum[i]+mcd[i]);
    }
    cout<<dp[n];
}
main() {
    // freopen("ok.inp","r",stdin);
    // freopen("ok.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    // cout<<clock()/1000.0;
}
// mcd[i]>=sum[j]+mcd[j]

Compilation message

segments.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   53 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 2 ms 2396 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2552 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 2 ms 2396 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2552 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 29 ms 4836 KB Output is correct
47 Correct 39 ms 4732 KB Output is correct
48 Correct 34 ms 4700 KB Output is correct
49 Correct 33 ms 4692 KB Output is correct
50 Correct 32 ms 4688 KB Output is correct
51 Correct 39 ms 4620 KB Output is correct
52 Correct 19 ms 3676 KB Output is correct
53 Correct 11 ms 3196 KB Output is correct
54 Correct 35 ms 4724 KB Output is correct
55 Correct 39 ms 4692 KB Output is correct
56 Correct 30 ms 4692 KB Output is correct
57 Correct 31 ms 4692 KB Output is correct
58 Correct 32 ms 4688 KB Output is correct
59 Correct 30 ms 4688 KB Output is correct
60 Correct 33 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 2 ms 2396 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2552 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 29 ms 4836 KB Output is correct
47 Correct 39 ms 4732 KB Output is correct
48 Correct 34 ms 4700 KB Output is correct
49 Correct 33 ms 4692 KB Output is correct
50 Correct 32 ms 4688 KB Output is correct
51 Correct 39 ms 4620 KB Output is correct
52 Correct 19 ms 3676 KB Output is correct
53 Correct 11 ms 3196 KB Output is correct
54 Correct 35 ms 4724 KB Output is correct
55 Correct 39 ms 4692 KB Output is correct
56 Correct 30 ms 4692 KB Output is correct
57 Correct 31 ms 4692 KB Output is correct
58 Correct 32 ms 4688 KB Output is correct
59 Correct 30 ms 4688 KB Output is correct
60 Correct 33 ms 4688 KB Output is correct
61 Runtime error 1 ms 604 KB Execution killed with signal 11
62 Halted 0 ms 0 KB -