Submission #370521

# Submission time Handle Problem Language Result Execution time Memory
370521 2021-02-24T05:03:41 Z daniel920712 Bigger segments (IZhO19_segments) C++14
100 / 100
622 ms 52204 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <utility>
#include <utility>
#include <time.h>

using namespace std;
long long all[500005];
pair < long long ,long long > DP[500005];
long long sum[500005]={0},N;
struct A
{
    long long nxl,nxr;
    pair < long long , long long > ans;
    pair < long long , long long > tt;
    long long here;
    long long rnd;
}Node[500005];
long long root=0;
void UPD(long long here)
{
    Node[here].ans=max(Node[Node[here].nxl].ans,Node[Node[here].nxr].ans);
    Node[here].ans=max(Node[here].ans,Node[here].tt);
}
void New(long long here,long long con,pair < long long ,long long > ans)
{
    Node[here].ans=Node[here].tt=ans;
    Node[here].here=con;
    Node[here].nxl=0;
    Node[here].nxr=0;
    Node[here].rnd=rand();
}
pair < long long , long long > split(long long here,long long con)
{
    pair < long long , long long > tt;
    if(here==0) return make_pair(0,0);
    //printf("%lld\n",here);
    if(con>=Node[here].here)
    {
        tt=split(Node[here].nxr,con);
        Node[here].nxr=tt.first;
        tt.first=here;
        UPD(here);
    }
    else
    {
        tt=split(Node[here].nxl,con);
        Node[here].nxl=tt.second;
        tt.second=here;
        UPD(here);
    }
    return tt;
}
long long Merge(long long a,long long b)
{

    if(a==0) return b;
    else if(b==0) return a;
    if(Node[a].here>Node[b].here)
    {
        //printf("%lld %lld\n",Node[a].here,Node[b].here);
        while(1);
    }
    //printf("%lld %lld\n",a,b);
    if(Node[a].rnd>Node[b].rnd)
    {
        Node[a].nxr=Merge(Node[a].nxr,b);
        UPD(a);
        return a;
    }
    else
    {
        Node[b].nxl=Merge(a,Node[b].nxl);
        UPD(b);
        return b;
    }
}
int main()
{
    srand(time(NULL));
    long long i,j,k,ans=0,tt=0;
    scanf("%lld",&N);
    for(i=1;i<=N;i++)
    {
        scanf("%lld",&all[i]);
        sum[i]=all[i]+sum[i-1];
    }

    Node[0].ans=make_pair(-1e18,-1e18);
    Node[0].tt=make_pair(-1e18,-1e18);
    New(N+1,0,make_pair(0,0));
    root=Merge(root,N+1);
    for(i=1;i<=N;i++)
    {
        //printf("aa %lld\n",i);
        pair < long long , long long > aa,bb;
        bb=split(root,sum[i]);
        aa=Node[bb.first].ans;

        //printf("%lld %lld %lld\n",bb.first,aa.first,aa.second);

        DP[i].first=aa.first+1;
        DP[i].second=sum[i]-sum[aa.second];

        New(i,DP[i].second+sum[i],make_pair(DP[i].first,i));

        root=Merge(bb.first,bb.second);

        bb=split(root,DP[i].second+sum[i]);

         root=Merge(Merge(bb.first,i),bb.second);


        tt=max(tt,DP[i].first);
        //printf("%lld %lld\n",DP[i].first,DP[i].second);
    }
    printf("%lld\n",tt);
    return 0;
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:83:17: warning: unused variable 'j' [-Wunused-variable]
   83 |     long long i,j,k,ans=0,tt=0;
      |                 ^
segments.cpp:83:19: warning: unused variable 'k' [-Wunused-variable]
   83 |     long long i,j,k,ans=0,tt=0;
      |                   ^
segments.cpp:83:21: warning: unused variable 'ans' [-Wunused-variable]
   83 |     long long i,j,k,ans=0,tt=0;
      |                     ^~~
segments.cpp:84:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   84 |     scanf("%lld",&N);
      |     ~~~~~^~~~~~~~~~~
segments.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   87 |         scanf("%lld",&all[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 31596 KB Output is correct
2 Correct 17 ms 31596 KB Output is correct
3 Correct 17 ms 31596 KB Output is correct
4 Correct 17 ms 31596 KB Output is correct
5 Correct 17 ms 31596 KB Output is correct
6 Correct 18 ms 31596 KB Output is correct
7 Correct 17 ms 31596 KB Output is correct
8 Correct 17 ms 31596 KB Output is correct
9 Correct 18 ms 31596 KB Output is correct
10 Correct 18 ms 31596 KB Output is correct
11 Correct 18 ms 31596 KB Output is correct
12 Correct 17 ms 31596 KB Output is correct
13 Correct 18 ms 31596 KB Output is correct
14 Correct 17 ms 31596 KB Output is correct
15 Correct 17 ms 31596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 31596 KB Output is correct
2 Correct 17 ms 31596 KB Output is correct
3 Correct 17 ms 31596 KB Output is correct
4 Correct 17 ms 31596 KB Output is correct
5 Correct 17 ms 31596 KB Output is correct
6 Correct 18 ms 31596 KB Output is correct
7 Correct 17 ms 31596 KB Output is correct
8 Correct 17 ms 31596 KB Output is correct
9 Correct 18 ms 31596 KB Output is correct
10 Correct 18 ms 31596 KB Output is correct
11 Correct 18 ms 31596 KB Output is correct
12 Correct 17 ms 31596 KB Output is correct
13 Correct 18 ms 31596 KB Output is correct
14 Correct 17 ms 31596 KB Output is correct
15 Correct 17 ms 31596 KB Output is correct
16 Correct 18 ms 31724 KB Output is correct
17 Correct 18 ms 31724 KB Output is correct
18 Correct 18 ms 31724 KB Output is correct
19 Correct 18 ms 31724 KB Output is correct
20 Correct 17 ms 31724 KB Output is correct
21 Correct 18 ms 31724 KB Output is correct
22 Correct 18 ms 31724 KB Output is correct
23 Correct 18 ms 31724 KB Output is correct
24 Correct 18 ms 31724 KB Output is correct
25 Correct 18 ms 31724 KB Output is correct
26 Correct 18 ms 31724 KB Output is correct
27 Correct 18 ms 31724 KB Output is correct
28 Correct 19 ms 31724 KB Output is correct
29 Correct 18 ms 31732 KB Output is correct
30 Correct 17 ms 31724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 31596 KB Output is correct
2 Correct 17 ms 31596 KB Output is correct
3 Correct 17 ms 31596 KB Output is correct
4 Correct 17 ms 31596 KB Output is correct
5 Correct 17 ms 31596 KB Output is correct
6 Correct 18 ms 31596 KB Output is correct
7 Correct 17 ms 31596 KB Output is correct
8 Correct 17 ms 31596 KB Output is correct
9 Correct 18 ms 31596 KB Output is correct
10 Correct 18 ms 31596 KB Output is correct
11 Correct 18 ms 31596 KB Output is correct
12 Correct 17 ms 31596 KB Output is correct
13 Correct 18 ms 31596 KB Output is correct
14 Correct 17 ms 31596 KB Output is correct
15 Correct 17 ms 31596 KB Output is correct
16 Correct 18 ms 31724 KB Output is correct
17 Correct 18 ms 31724 KB Output is correct
18 Correct 18 ms 31724 KB Output is correct
19 Correct 18 ms 31724 KB Output is correct
20 Correct 17 ms 31724 KB Output is correct
21 Correct 18 ms 31724 KB Output is correct
22 Correct 18 ms 31724 KB Output is correct
23 Correct 18 ms 31724 KB Output is correct
24 Correct 18 ms 31724 KB Output is correct
25 Correct 18 ms 31724 KB Output is correct
26 Correct 18 ms 31724 KB Output is correct
27 Correct 18 ms 31724 KB Output is correct
28 Correct 19 ms 31724 KB Output is correct
29 Correct 18 ms 31732 KB Output is correct
30 Correct 17 ms 31724 KB Output is correct
31 Correct 19 ms 31724 KB Output is correct
32 Correct 20 ms 31724 KB Output is correct
33 Correct 20 ms 31724 KB Output is correct
34 Correct 20 ms 31852 KB Output is correct
35 Correct 19 ms 31724 KB Output is correct
36 Correct 20 ms 31724 KB Output is correct
37 Correct 20 ms 31724 KB Output is correct
38 Correct 19 ms 31724 KB Output is correct
39 Correct 20 ms 31852 KB Output is correct
40 Correct 21 ms 31724 KB Output is correct
41 Correct 19 ms 31724 KB Output is correct
42 Correct 20 ms 31852 KB Output is correct
43 Correct 20 ms 31724 KB Output is correct
44 Correct 18 ms 31724 KB Output is correct
45 Correct 20 ms 31724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 31596 KB Output is correct
2 Correct 17 ms 31596 KB Output is correct
3 Correct 17 ms 31596 KB Output is correct
4 Correct 17 ms 31596 KB Output is correct
5 Correct 17 ms 31596 KB Output is correct
6 Correct 18 ms 31596 KB Output is correct
7 Correct 17 ms 31596 KB Output is correct
8 Correct 17 ms 31596 KB Output is correct
9 Correct 18 ms 31596 KB Output is correct
10 Correct 18 ms 31596 KB Output is correct
11 Correct 18 ms 31596 KB Output is correct
12 Correct 17 ms 31596 KB Output is correct
13 Correct 18 ms 31596 KB Output is correct
14 Correct 17 ms 31596 KB Output is correct
15 Correct 17 ms 31596 KB Output is correct
16 Correct 18 ms 31724 KB Output is correct
17 Correct 18 ms 31724 KB Output is correct
18 Correct 18 ms 31724 KB Output is correct
19 Correct 18 ms 31724 KB Output is correct
20 Correct 17 ms 31724 KB Output is correct
21 Correct 18 ms 31724 KB Output is correct
22 Correct 18 ms 31724 KB Output is correct
23 Correct 18 ms 31724 KB Output is correct
24 Correct 18 ms 31724 KB Output is correct
25 Correct 18 ms 31724 KB Output is correct
26 Correct 18 ms 31724 KB Output is correct
27 Correct 18 ms 31724 KB Output is correct
28 Correct 19 ms 31724 KB Output is correct
29 Correct 18 ms 31732 KB Output is correct
30 Correct 17 ms 31724 KB Output is correct
31 Correct 19 ms 31724 KB Output is correct
32 Correct 20 ms 31724 KB Output is correct
33 Correct 20 ms 31724 KB Output is correct
34 Correct 20 ms 31852 KB Output is correct
35 Correct 19 ms 31724 KB Output is correct
36 Correct 20 ms 31724 KB Output is correct
37 Correct 20 ms 31724 KB Output is correct
38 Correct 19 ms 31724 KB Output is correct
39 Correct 20 ms 31852 KB Output is correct
40 Correct 21 ms 31724 KB Output is correct
41 Correct 19 ms 31724 KB Output is correct
42 Correct 20 ms 31852 KB Output is correct
43 Correct 20 ms 31724 KB Output is correct
44 Correct 18 ms 31724 KB Output is correct
45 Correct 20 ms 31724 KB Output is correct
46 Correct 72 ms 35180 KB Output is correct
47 Correct 131 ms 35308 KB Output is correct
48 Correct 104 ms 35564 KB Output is correct
49 Correct 95 ms 35692 KB Output is correct
50 Correct 69 ms 35820 KB Output is correct
51 Correct 114 ms 35924 KB Output is correct
52 Correct 71 ms 33644 KB Output is correct
53 Correct 45 ms 32876 KB Output is correct
54 Correct 110 ms 35052 KB Output is correct
55 Correct 111 ms 35820 KB Output is correct
56 Correct 65 ms 35308 KB Output is correct
57 Correct 92 ms 35180 KB Output is correct
58 Correct 86 ms 35180 KB Output is correct
59 Correct 65 ms 35308 KB Output is correct
60 Correct 102 ms 35308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 31596 KB Output is correct
2 Correct 17 ms 31596 KB Output is correct
3 Correct 17 ms 31596 KB Output is correct
4 Correct 17 ms 31596 KB Output is correct
5 Correct 17 ms 31596 KB Output is correct
6 Correct 18 ms 31596 KB Output is correct
7 Correct 17 ms 31596 KB Output is correct
8 Correct 17 ms 31596 KB Output is correct
9 Correct 18 ms 31596 KB Output is correct
10 Correct 18 ms 31596 KB Output is correct
11 Correct 18 ms 31596 KB Output is correct
12 Correct 17 ms 31596 KB Output is correct
13 Correct 18 ms 31596 KB Output is correct
14 Correct 17 ms 31596 KB Output is correct
15 Correct 17 ms 31596 KB Output is correct
16 Correct 18 ms 31724 KB Output is correct
17 Correct 18 ms 31724 KB Output is correct
18 Correct 18 ms 31724 KB Output is correct
19 Correct 18 ms 31724 KB Output is correct
20 Correct 17 ms 31724 KB Output is correct
21 Correct 18 ms 31724 KB Output is correct
22 Correct 18 ms 31724 KB Output is correct
23 Correct 18 ms 31724 KB Output is correct
24 Correct 18 ms 31724 KB Output is correct
25 Correct 18 ms 31724 KB Output is correct
26 Correct 18 ms 31724 KB Output is correct
27 Correct 18 ms 31724 KB Output is correct
28 Correct 19 ms 31724 KB Output is correct
29 Correct 18 ms 31732 KB Output is correct
30 Correct 17 ms 31724 KB Output is correct
31 Correct 19 ms 31724 KB Output is correct
32 Correct 20 ms 31724 KB Output is correct
33 Correct 20 ms 31724 KB Output is correct
34 Correct 20 ms 31852 KB Output is correct
35 Correct 19 ms 31724 KB Output is correct
36 Correct 20 ms 31724 KB Output is correct
37 Correct 20 ms 31724 KB Output is correct
38 Correct 19 ms 31724 KB Output is correct
39 Correct 20 ms 31852 KB Output is correct
40 Correct 21 ms 31724 KB Output is correct
41 Correct 19 ms 31724 KB Output is correct
42 Correct 20 ms 31852 KB Output is correct
43 Correct 20 ms 31724 KB Output is correct
44 Correct 18 ms 31724 KB Output is correct
45 Correct 20 ms 31724 KB Output is correct
46 Correct 72 ms 35180 KB Output is correct
47 Correct 131 ms 35308 KB Output is correct
48 Correct 104 ms 35564 KB Output is correct
49 Correct 95 ms 35692 KB Output is correct
50 Correct 69 ms 35820 KB Output is correct
51 Correct 114 ms 35924 KB Output is correct
52 Correct 71 ms 33644 KB Output is correct
53 Correct 45 ms 32876 KB Output is correct
54 Correct 110 ms 35052 KB Output is correct
55 Correct 111 ms 35820 KB Output is correct
56 Correct 65 ms 35308 KB Output is correct
57 Correct 92 ms 35180 KB Output is correct
58 Correct 86 ms 35180 KB Output is correct
59 Correct 65 ms 35308 KB Output is correct
60 Correct 102 ms 35308 KB Output is correct
61 Correct 412 ms 49444 KB Output is correct
62 Correct 451 ms 49408 KB Output is correct
63 Correct 622 ms 49644 KB Output is correct
64 Correct 488 ms 51820 KB Output is correct
65 Correct 291 ms 52204 KB Output is correct
66 Correct 541 ms 52148 KB Output is correct
67 Correct 438 ms 48244 KB Output is correct
68 Correct 214 ms 39788 KB Output is correct
69 Correct 518 ms 48492 KB Output is correct
70 Correct 532 ms 52204 KB Output is correct
71 Correct 281 ms 49260 KB Output is correct
72 Correct 404 ms 49644 KB Output is correct
73 Correct 330 ms 50284 KB Output is correct
74 Correct 288 ms 50540 KB Output is correct
75 Correct 336 ms 50796 KB Output is correct