Submission #341900

# Submission time Handle Problem Language Result Execution time Memory
341900 2020-12-31T12:08:58 Z katearima Bigger segments (IZhO19_segments) C++14
100 / 100
252 ms 21972 KB
#include <bits/stdc++.h>
#define int long long
#define sum  first
#define ind second
using namespace std;
const int N=500005;
int a[N],sums[N], oldS, n;
int ans[N];
priority_queue<pair<int, int> , vector<pair<int, int>> , greater<pair<int, int>>> pq;
main(){
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    sums[1]=a[1];
    for(int i=2; i<=n; i++){
        sums[i]=a[i]+sums[i-1];
    }
    int sp=0; // starting point of segment
    for(int i=1; i<=n; i++){
        //cout<<sums[i]<<endl;
      while(pq.size()!=0 && pq.top().sum <= sums[i]){
            //cout<<pq.top().sum<<" "<<sums[i]<<" "<<pq.top().ind<<" "<<sp<<endl;
            int j=pq.top().ind;
            if(ans[j]>ans[sp]) sp=j;
            else if(ans[j]==ans[sp]) sp=max(j, sp);
            pq.pop();

      }
       ans[i] = ans[sp]+1;
       //cout<<sums[i]<<" "<<sums[sp];
       //cout<<2*sums[i]-sums[sp]<<endl;
       pq.push(make_pair(2*sums[i]-sums[sp], i));
    }
    cout<<ans[n]<<endl;
}

Compilation message

segments.cpp:10:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main(){
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 236 KB Output is correct
20 Correct 1 ms 236 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 236 KB Output is correct
20 Correct 1 ms 236 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 236 KB Output is correct
20 Correct 1 ms 236 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 2 ms 364 KB Output is correct
46 Correct 27 ms 4960 KB Output is correct
47 Correct 38 ms 3564 KB Output is correct
48 Correct 46 ms 3584 KB Output is correct
49 Correct 45 ms 4076 KB Output is correct
50 Correct 50 ms 3692 KB Output is correct
51 Correct 51 ms 3692 KB Output is correct
52 Correct 26 ms 2028 KB Output is correct
53 Correct 15 ms 1388 KB Output is correct
54 Correct 26 ms 2924 KB Output is correct
55 Correct 50 ms 3692 KB Output is correct
56 Correct 28 ms 3320 KB Output is correct
57 Correct 30 ms 4068 KB Output is correct
58 Correct 30 ms 3684 KB Output is correct
59 Correct 31 ms 3308 KB Output is correct
60 Correct 34 ms 3308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 236 KB Output is correct
20 Correct 1 ms 236 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 2 ms 364 KB Output is correct
46 Correct 27 ms 4960 KB Output is correct
47 Correct 38 ms 3564 KB Output is correct
48 Correct 46 ms 3584 KB Output is correct
49 Correct 45 ms 4076 KB Output is correct
50 Correct 50 ms 3692 KB Output is correct
51 Correct 51 ms 3692 KB Output is correct
52 Correct 26 ms 2028 KB Output is correct
53 Correct 15 ms 1388 KB Output is correct
54 Correct 26 ms 2924 KB Output is correct
55 Correct 50 ms 3692 KB Output is correct
56 Correct 28 ms 3320 KB Output is correct
57 Correct 30 ms 4068 KB Output is correct
58 Correct 30 ms 3684 KB Output is correct
59 Correct 31 ms 3308 KB Output is correct
60 Correct 34 ms 3308 KB Output is correct
61 Correct 133 ms 21972 KB Output is correct
62 Correct 151 ms 18196 KB Output is correct
63 Correct 190 ms 16092 KB Output is correct
64 Correct 220 ms 16620 KB Output is correct
65 Correct 217 ms 16876 KB Output is correct
66 Correct 252 ms 16876 KB Output is correct
67 Correct 200 ms 13548 KB Output is correct
68 Correct 101 ms 7020 KB Output is correct
69 Correct 132 ms 13196 KB Output is correct
70 Correct 249 ms 17004 KB Output is correct
71 Correct 123 ms 14060 KB Output is correct
72 Correct 154 ms 17624 KB Output is correct
73 Correct 161 ms 16348 KB Output is correct
74 Correct 169 ms 15340 KB Output is correct
75 Correct 172 ms 15340 KB Output is correct