Submission #956094

# Submission time Handle Problem Language Result Execution time Memory
956094 2024-04-01T04:44:35 Z vjudge1 Bigger segments (IZhO19_segments) C++17
100 / 100
317 ms 38996 KB
#include <bits/stdc++.h>
#define getbit(i, j) ((i >> j) & 1)
#define maxn 500005
#define name "main"
using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

long long GetRandom(long long l, long long r)
{
    return uniform_int_distribution<long long> (l, r)(rng);
}

int n,a[maxn],dp[maxn];
long long sum[maxn],lazy[maxn*4],mod=-1e16;
pair<long long,long long> st[maxn*4];

void build(int id,int l,int r)
{
    if(l>r) return;
    if(l==r)
    {
        st[id]={mod,l};
        return;
    }
    int mid=(l+r)/2;
    build(id*2,l,mid);
    build(id*2+1,mid+1,r);
    st[id]={mod,l};
}

void lazy1(int id)
{
    long long val=lazy[id];
    lazy[id]=0;
    st[id*2].first+=val;
    st[id*2+1].first+=val;
    lazy[id*2]+=val;
    lazy[id*2+1]+=val;
}

void tinh(int id,int l,int r,int vt,long long val)
{
    if(l>vt||r<vt) return;
    if(l==r)
    {
        st[id].first=val;
        return;
    }
    lazy1(id);
    int mid=(l+r)/2;
    tinh(id*2,l,mid,vt,val);
    tinh(id*2+1,mid+1,r,vt,val);
    st[id]=st[id*2];
    if(st[id].first<st[id*2+1].first) st[id]=st[id*2+1];
}

void update(int id,int l,int r,int d,int c,long long val)
{
    if(l>c||r<d) return;
    if(l>=d&&r<=c)
    {
        st[id].first+=val;
        lazy[id]+=val;
        return;
    }
    int mid=(l+r)/2;
    lazy1(id);
    update(id*2,l,mid,d,c,val);
    update(id*2+1,mid+1,r,d,c,val);
    st[id]=st[id*2];
    if(st[id].first<st[id*2+1].first) st[id]=st[id*2+1];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    if(fopen(name".inp","r"))
    {
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        sum[i]=sum[i-1]+a[i];
    }
    int vt=0;
    build(1,1,n);

    for(int i=1;i<=n;i++)
    {
        update(1,1,n,1,i-1,a[i]);
        while(st[1].first>=0)
        {
            int u=st[1].second;
            if(dp[vt]<dp[u]) vt=u;
            else if(dp[vt]==dp[u]) vt=max(vt,u);
            tinh(1,1,n,u,mod);
        }
        dp[i]=dp[vt]+1;
        long long val=sum[i]-sum[vt];
        tinh(1,1,n,i,-val);
    }
    cout<<dp[n];

}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
segments.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 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 2648 KB Output is correct
8 Correct 1 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 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 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 2648 KB Output is correct
8 Correct 1 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 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 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 2396 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 2392 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 2396 KB Output is correct
30 Correct 1 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 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 2648 KB Output is correct
8 Correct 1 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 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 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 2396 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 2392 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 2396 KB Output is correct
30 Correct 1 ms 2516 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2780 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 2 ms 2652 KB Output is correct
39 Correct 2 ms 2760 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 2 ms 2652 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 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 2648 KB Output is correct
8 Correct 1 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 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 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 2396 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 2392 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 2396 KB Output is correct
30 Correct 1 ms 2516 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2780 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 2 ms 2652 KB Output is correct
39 Correct 2 ms 2760 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 2 ms 2652 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 37 ms 13744 KB Output is correct
47 Correct 54 ms 13648 KB Output is correct
48 Correct 61 ms 14140 KB Output is correct
49 Correct 55 ms 14164 KB Output is correct
50 Correct 56 ms 14188 KB Output is correct
51 Correct 59 ms 14164 KB Output is correct
52 Correct 28 ms 6736 KB Output is correct
53 Correct 17 ms 5724 KB Output is correct
54 Correct 60 ms 13652 KB Output is correct
55 Correct 58 ms 14164 KB Output is correct
56 Correct 54 ms 13756 KB Output is correct
57 Correct 53 ms 13652 KB Output is correct
58 Correct 57 ms 13696 KB Output is correct
59 Correct 55 ms 13936 KB Output is correct
60 Correct 54 ms 13908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 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 2648 KB Output is correct
8 Correct 1 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 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 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 2396 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 2392 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 2396 KB Output is correct
30 Correct 1 ms 2516 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2780 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 2 ms 2652 KB Output is correct
39 Correct 2 ms 2760 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 2 ms 2652 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 37 ms 13744 KB Output is correct
47 Correct 54 ms 13648 KB Output is correct
48 Correct 61 ms 14140 KB Output is correct
49 Correct 55 ms 14164 KB Output is correct
50 Correct 56 ms 14188 KB Output is correct
51 Correct 59 ms 14164 KB Output is correct
52 Correct 28 ms 6736 KB Output is correct
53 Correct 17 ms 5724 KB Output is correct
54 Correct 60 ms 13652 KB Output is correct
55 Correct 58 ms 14164 KB Output is correct
56 Correct 54 ms 13756 KB Output is correct
57 Correct 53 ms 13652 KB Output is correct
58 Correct 57 ms 13696 KB Output is correct
59 Correct 55 ms 13936 KB Output is correct
60 Correct 54 ms 13908 KB Output is correct
61 Correct 198 ms 36436 KB Output is correct
62 Correct 237 ms 36432 KB Output is correct
63 Correct 293 ms 37152 KB Output is correct
64 Correct 317 ms 38360 KB Output is correct
65 Correct 305 ms 38796 KB Output is correct
66 Correct 311 ms 38456 KB Output is correct
67 Correct 264 ms 37620 KB Output is correct
68 Correct 121 ms 21476 KB Output is correct
69 Correct 295 ms 35664 KB Output is correct
70 Correct 306 ms 38996 KB Output is correct
71 Correct 285 ms 36556 KB Output is correct
72 Correct 298 ms 36964 KB Output is correct
73 Correct 300 ms 37096 KB Output is correct
74 Correct 303 ms 37716 KB Output is correct
75 Correct 304 ms 37556 KB Output is correct