Submission #957150

# Submission time Handle Problem Language Result Execution time Memory
957150 2024-04-03T05:15:28 Z Requiem Bigger segments (IZhO19_segments) C++17
100 / 100
204 ms 21344 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 = 500005;
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;
}

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 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 2 ms 4620 KB Output is correct
34 Correct 2 ms 4444 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 2 ms 4444 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 2 ms 4620 KB Output is correct
34 Correct 2 ms 4444 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 2 ms 4444 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 30 ms 13484 KB Output is correct
47 Correct 36 ms 13392 KB Output is correct
48 Correct 41 ms 13400 KB Output is correct
49 Correct 34 ms 13396 KB Output is correct
50 Correct 32 ms 13404 KB Output is correct
51 Correct 39 ms 13488 KB Output is correct
52 Correct 20 ms 11100 KB Output is correct
53 Correct 12 ms 7004 KB Output is correct
54 Correct 35 ms 13272 KB Output is correct
55 Correct 39 ms 13404 KB Output is correct
56 Correct 30 ms 13404 KB Output is correct
57 Correct 32 ms 13392 KB Output is correct
58 Correct 32 ms 13404 KB Output is correct
59 Correct 31 ms 13448 KB Output is correct
60 Correct 34 ms 13416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 2 ms 4620 KB Output is correct
34 Correct 2 ms 4444 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 2 ms 4444 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 30 ms 13484 KB Output is correct
47 Correct 36 ms 13392 KB Output is correct
48 Correct 41 ms 13400 KB Output is correct
49 Correct 34 ms 13396 KB Output is correct
50 Correct 32 ms 13404 KB Output is correct
51 Correct 39 ms 13488 KB Output is correct
52 Correct 20 ms 11100 KB Output is correct
53 Correct 12 ms 7004 KB Output is correct
54 Correct 35 ms 13272 KB Output is correct
55 Correct 39 ms 13404 KB Output is correct
56 Correct 30 ms 13404 KB Output is correct
57 Correct 32 ms 13392 KB Output is correct
58 Correct 32 ms 13404 KB Output is correct
59 Correct 31 ms 13448 KB Output is correct
60 Correct 34 ms 13416 KB Output is correct
61 Correct 153 ms 21072 KB Output is correct
62 Correct 175 ms 20944 KB Output is correct
63 Correct 196 ms 21344 KB Output is correct
64 Correct 190 ms 21076 KB Output is correct
65 Correct 173 ms 21072 KB Output is correct
66 Correct 204 ms 20908 KB Output is correct
67 Correct 159 ms 20176 KB Output is correct
68 Correct 76 ms 15444 KB Output is correct
69 Correct 185 ms 21076 KB Output is correct
70 Correct 201 ms 21060 KB Output is correct
71 Correct 154 ms 20928 KB Output is correct
72 Correct 168 ms 20936 KB Output is correct
73 Correct 183 ms 21072 KB Output is correct
74 Correct 161 ms 20936 KB Output is correct
75 Correct 169 ms 20912 KB Output is correct