# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
377168 | 2021-03-13T07:09:53 Z | jamielim | Bigger segments (IZhO19_segments) | C++14 | 94 ms | 24188 KB |
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb emplace_back #define ALL(x) x.begin(),x.end() #define SZ(x) (int)x.size() typedef long long ll; typedef pair<int,int> ii; typedef pair<ii,ii> i4; const int MOD=1000000007; const int INF=1012345678; const ll LLINF=1012345678012345678LL; const double PI=3.1415926536; const double EPS=1e-14; int n; ll arr[500005]; ll pre[500005]; ll sz[500005]; int ans[500005]; int main(){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%lld",&arr[i]); if(i==0)pre[0]=arr[0]; else pre[i]=pre[i-1]+arr[i]; } deque<pair<ll,int> > q; sz[0]=arr[0];ans[0]=1; q.pb(sz[0]+pre[0],0); for(int i=1;i<n;i++){ sz[i]=sz[i-1]+arr[i]; ans[i]=ans[i-1]; while(!q.empty()&&q.front().fi<=pre[i]){ sz[i]=pre[i]-pre[q.front().se]; ans[i]=ans[q.front().se]+1; q.pop_front(); } while(!q.empty()&&q.back().fi>=sz[i]+pre[i])q.pop_back(); q.pb(sz[i]+pre[i],i); } printf("%d",ans[n-1]); } // sz[j]<=pre[i]-pre[j] -> sz[j]+pre[j]<=pre[i]
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 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 | 384 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 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 | 384 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 | 364 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 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 | 384 KB | Output is correct |
29 | Correct | 1 ms | 364 KB | Output is correct |
30 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 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 | 384 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 | 364 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 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 | 384 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 | 1 ms | 492 KB | Output is correct |
33 | Correct | 1 ms | 492 KB | Output is correct |
34 | Correct | 1 ms | 492 KB | Output is correct |
35 | Correct | 2 ms | 492 KB | Output is correct |
36 | Correct | 1 ms | 492 KB | Output is correct |
37 | Correct | 1 ms | 492 KB | Output is correct |
38 | Correct | 1 ms | 364 KB | Output is correct |
39 | Correct | 1 ms | 492 KB | Output is correct |
40 | Correct | 1 ms | 512 KB | Output is correct |
41 | Correct | 1 ms | 492 KB | Output is correct |
42 | Correct | 1 ms | 492 KB | Output is correct |
43 | Correct | 1 ms | 492 KB | Output is correct |
44 | Correct | 1 ms | 492 KB | Output is correct |
45 | Correct | 1 ms | 512 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 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 | 384 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 | 364 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 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 | 384 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 | 1 ms | 492 KB | Output is correct |
33 | Correct | 1 ms | 492 KB | Output is correct |
34 | Correct | 1 ms | 492 KB | Output is correct |
35 | Correct | 2 ms | 492 KB | Output is correct |
36 | Correct | 1 ms | 492 KB | Output is correct |
37 | Correct | 1 ms | 492 KB | Output is correct |
38 | Correct | 1 ms | 364 KB | Output is correct |
39 | Correct | 1 ms | 492 KB | Output is correct |
40 | Correct | 1 ms | 512 KB | Output is correct |
41 | Correct | 1 ms | 492 KB | Output is correct |
42 | Correct | 1 ms | 492 KB | Output is correct |
43 | Correct | 1 ms | 492 KB | Output is correct |
44 | Correct | 1 ms | 492 KB | Output is correct |
45 | Correct | 1 ms | 512 KB | Output is correct |
46 | Correct | 14 ms | 5100 KB | Output is correct |
47 | Correct | 14 ms | 3692 KB | Output is correct |
48 | Correct | 20 ms | 3948 KB | Output is correct |
49 | Correct | 19 ms | 4204 KB | Output is correct |
50 | Correct | 17 ms | 4076 KB | Output is correct |
51 | Correct | 19 ms | 4076 KB | Output is correct |
52 | Correct | 10 ms | 2156 KB | Output is correct |
53 | Correct | 6 ms | 1516 KB | Output is correct |
54 | Correct | 14 ms | 3308 KB | Output is correct |
55 | Correct | 18 ms | 4076 KB | Output is correct |
56 | Correct | 14 ms | 3564 KB | Output is correct |
57 | Correct | 14 ms | 4204 KB | Output is correct |
58 | Correct | 14 ms | 3820 KB | Output is correct |
59 | Correct | 14 ms | 3692 KB | Output is correct |
60 | Correct | 14 ms | 3692 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 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 | 384 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 | 364 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 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 | 384 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 | 1 ms | 492 KB | Output is correct |
33 | Correct | 1 ms | 492 KB | Output is correct |
34 | Correct | 1 ms | 492 KB | Output is correct |
35 | Correct | 2 ms | 492 KB | Output is correct |
36 | Correct | 1 ms | 492 KB | Output is correct |
37 | Correct | 1 ms | 492 KB | Output is correct |
38 | Correct | 1 ms | 364 KB | Output is correct |
39 | Correct | 1 ms | 492 KB | Output is correct |
40 | Correct | 1 ms | 512 KB | Output is correct |
41 | Correct | 1 ms | 492 KB | Output is correct |
42 | Correct | 1 ms | 492 KB | Output is correct |
43 | Correct | 1 ms | 492 KB | Output is correct |
44 | Correct | 1 ms | 492 KB | Output is correct |
45 | Correct | 1 ms | 512 KB | Output is correct |
46 | Correct | 14 ms | 5100 KB | Output is correct |
47 | Correct | 14 ms | 3692 KB | Output is correct |
48 | Correct | 20 ms | 3948 KB | Output is correct |
49 | Correct | 19 ms | 4204 KB | Output is correct |
50 | Correct | 17 ms | 4076 KB | Output is correct |
51 | Correct | 19 ms | 4076 KB | Output is correct |
52 | Correct | 10 ms | 2156 KB | Output is correct |
53 | Correct | 6 ms | 1516 KB | Output is correct |
54 | Correct | 14 ms | 3308 KB | Output is correct |
55 | Correct | 18 ms | 4076 KB | Output is correct |
56 | Correct | 14 ms | 3564 KB | Output is correct |
57 | Correct | 14 ms | 4204 KB | Output is correct |
58 | Correct | 14 ms | 3820 KB | Output is correct |
59 | Correct | 14 ms | 3692 KB | Output is correct |
60 | Correct | 14 ms | 3692 KB | Output is correct |
61 | Correct | 69 ms | 24188 KB | Output is correct |
62 | Correct | 67 ms | 20204 KB | Output is correct |
63 | Correct | 71 ms | 17388 KB | Output is correct |
64 | Correct | 92 ms | 18540 KB | Output is correct |
65 | Correct | 84 ms | 18924 KB | Output is correct |
66 | Correct | 93 ms | 18796 KB | Output is correct |
67 | Correct | 71 ms | 15212 KB | Output is correct |
68 | Correct | 37 ms | 7788 KB | Output is correct |
69 | Correct | 67 ms | 15084 KB | Output is correct |
70 | Correct | 94 ms | 18924 KB | Output is correct |
71 | Correct | 64 ms | 15980 KB | Output is correct |
72 | Correct | 87 ms | 19832 KB | Output is correct |
73 | Correct | 72 ms | 18156 KB | Output is correct |
74 | Correct | 72 ms | 17260 KB | Output is correct |
75 | Correct | 73 ms | 17344 KB | Output is correct |