답안 #201052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201052 2020-02-09T08:24:00 Z a1_N Bigger segments (IZhO19_segments) C++17
37 / 100
171 ms 38464 KB
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int N = (int)5e5 + 5;
const long long M = (long long)6e14;
    
int n,timer = 1,a[N],L[N * 20],R[N * 20];
pair<int,int> t[N * 4];
long long pref[N];
pair<int,long long> dp[N];
pair<int,int> ZeroPair = {0,0};

void upd(int v,long long tl,long long tr,long long pos,pair<int,int> val){
	if(tl == tr){
		t[v] = val;
		return;
	}
	long long tm = (tl + tr) >> 1;
	if(pos <= tm){
		if(!L[v]) L[v] = ++timer;
		upd(L[v],tl,tm,pos,val);
	}
	else{
		if(!R[v]) R[v] = ++timer;
		upd(R[v],tm + 1,tr,pos,val);
	}
	t[v] = max(t[L[v]],t[R[v]]);
}

pair<int,int> get(int v,long long tl,long long tr,long long l,long long r){
	if(l <= tl && tr <= r) return t[v];
	if(tl > r || tr < l) return ZeroPair;
	long long tm = (tl + tr) >> 1;
	return max(get(L[v],tl,tm,l,r),get(R[v],tm + 1,tr,l,r));
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		pref[i] = pref[i - 1] + a[i];
	}
	dp[1] = {1,a[1]};
	upd(1,1,M,pref[1] + dp[1].S,make_pair(dp[1].F,1));
	for(int i = 2; i <= n; i++){
		dp[i] = {dp[i - 1].F,dp[i - 1].S + a[i]};
		pair<int,int> cur = get(1,1,M,1,pref[i]);
		if(cur.F > 0) dp[i] = {cur.F + 1,pref[i] - pref[cur.S]};
		upd(1,1,M,pref[i] + dp[i].S,make_pair(dp[i].F,i));	
	}
	cout << dp[n].F;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 508 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 508 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 6 ms 632 KB Output is correct
17 Correct 6 ms 504 KB Output is correct
18 Correct 5 ms 632 KB Output is correct
19 Correct 5 ms 632 KB Output is correct
20 Correct 6 ms 632 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Correct 5 ms 636 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 6 ms 632 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 6 ms 460 KB Output is correct
28 Correct 6 ms 380 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 508 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 6 ms 632 KB Output is correct
17 Correct 6 ms 504 KB Output is correct
18 Correct 5 ms 632 KB Output is correct
19 Correct 5 ms 632 KB Output is correct
20 Correct 6 ms 632 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Correct 5 ms 636 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 6 ms 632 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 6 ms 460 KB Output is correct
28 Correct 6 ms 380 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 9 ms 1272 KB Output is correct
32 Correct 10 ms 1400 KB Output is correct
33 Correct 10 ms 1656 KB Output is correct
34 Correct 10 ms 1532 KB Output is correct
35 Correct 11 ms 1912 KB Output is correct
36 Correct 10 ms 1912 KB Output is correct
37 Correct 9 ms 1656 KB Output is correct
38 Correct 8 ms 1400 KB Output is correct
39 Correct 9 ms 632 KB Output is correct
40 Correct 10 ms 1784 KB Output is correct
41 Correct 8 ms 632 KB Output is correct
42 Correct 7 ms 888 KB Output is correct
43 Correct 7 ms 632 KB Output is correct
44 Correct 8 ms 1144 KB Output is correct
45 Correct 9 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 508 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 6 ms 632 KB Output is correct
17 Correct 6 ms 504 KB Output is correct
18 Correct 5 ms 632 KB Output is correct
19 Correct 5 ms 632 KB Output is correct
20 Correct 6 ms 632 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Correct 5 ms 636 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 6 ms 632 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 6 ms 460 KB Output is correct
28 Correct 6 ms 380 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 9 ms 1272 KB Output is correct
32 Correct 10 ms 1400 KB Output is correct
33 Correct 10 ms 1656 KB Output is correct
34 Correct 10 ms 1532 KB Output is correct
35 Correct 11 ms 1912 KB Output is correct
36 Correct 10 ms 1912 KB Output is correct
37 Correct 9 ms 1656 KB Output is correct
38 Correct 8 ms 1400 KB Output is correct
39 Correct 9 ms 632 KB Output is correct
40 Correct 10 ms 1784 KB Output is correct
41 Correct 8 ms 632 KB Output is correct
42 Correct 7 ms 888 KB Output is correct
43 Correct 7 ms 632 KB Output is correct
44 Correct 8 ms 1144 KB Output is correct
45 Correct 9 ms 1016 KB Output is correct
46 Correct 139 ms 20216 KB Output is correct
47 Correct 143 ms 22776 KB Output is correct
48 Incorrect 171 ms 38464 KB Output isn't correct
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 508 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 6 ms 632 KB Output is correct
17 Correct 6 ms 504 KB Output is correct
18 Correct 5 ms 632 KB Output is correct
19 Correct 5 ms 632 KB Output is correct
20 Correct 6 ms 632 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Correct 5 ms 636 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 6 ms 632 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 6 ms 460 KB Output is correct
28 Correct 6 ms 380 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 9 ms 1272 KB Output is correct
32 Correct 10 ms 1400 KB Output is correct
33 Correct 10 ms 1656 KB Output is correct
34 Correct 10 ms 1532 KB Output is correct
35 Correct 11 ms 1912 KB Output is correct
36 Correct 10 ms 1912 KB Output is correct
37 Correct 9 ms 1656 KB Output is correct
38 Correct 8 ms 1400 KB Output is correct
39 Correct 9 ms 632 KB Output is correct
40 Correct 10 ms 1784 KB Output is correct
41 Correct 8 ms 632 KB Output is correct
42 Correct 7 ms 888 KB Output is correct
43 Correct 7 ms 632 KB Output is correct
44 Correct 8 ms 1144 KB Output is correct
45 Correct 9 ms 1016 KB Output is correct
46 Correct 139 ms 20216 KB Output is correct
47 Correct 143 ms 22776 KB Output is correct
48 Incorrect 171 ms 38464 KB Output isn't correct
49 Halted 0 ms 0 KB -