답안 #201374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201374 2020-02-10T10:32:08 Z guangxuan Bigger segments (IZhO19_segments) C++14
73 / 100
669 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

int a[500009];
long long rs[500009];
pair<int,long long> dp[500009];

struct node{
	pair<int,long long> v;
	node *l,*r;
	node():v({-1,-1}),l(NULL),r(NULL){}
	void up(long long s,long long e,long long x,pair<int,long long> uv){
		long long m = (s+e)/2;
		if(s==e){
			v = max(v,uv);return;
		}
		if(x>m){
			if(r==NULL)r = new node();
			r->up(m+1,e,x,uv);
		}
		else{
			if(l==NULL)l = new node();
			l->up(s,m,x,uv);
		}
		v = {-1,-1};
		if(r)v = max(v,r->v);
		if(l)v = max(v,l->v);
	}
	pair<int,long long> qu(long long s,long long e,long long x,long long y){
		long long m = (s+e)/2;
		if(s==x&&e==y)return v;
		if(x>m){
			if(r)return r->qu(m+1,e,x,y);
			else return {-1,-1};
		}
		if(y<=m){
			if(l)return l->qu(s,m,x,y);
			else return {-1,-1};
		}
		pair<int,long long> qv = {-1,-1};
		if(r)qv = max(qv,r->qu(m+1,e,m+1,y));
		if(l)qv = max(qv,l->qu(s,m,x,m));
		return qv;
	}
}*root;

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		rs[i+1]=rs[i]+a[i];
	}
	root = new node();
	root->up(0,(long long)5e14,0,{0,0});
	for(int i=1;i<=n;i++){
		pair<int,long long> res = root->qu(0,(long long)5e14,0,rs[i]); 
		dp[i] = {res.first,res.second - rs[i]};
		dp[i].first++;
		root->up(0,(long long)5e14,rs[i] - dp[i].second,{dp[i].first,rs[i]});
		//cout << dp[i].first << ' ' << dp[i].second << '\n';
		// cout << res.first << ' ' << res.second.first << ' ' << res.second.second << '\n';
	}
	printf("%d", dp[n].first);
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
segments.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 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 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 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 376 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 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 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 376 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 760 KB Output is correct
17 Correct 6 ms 888 KB Output is correct
18 Correct 7 ms 1016 KB Output is correct
19 Correct 6 ms 1016 KB Output is correct
20 Correct 6 ms 1016 KB Output is correct
21 Correct 6 ms 1144 KB Output is correct
22 Correct 6 ms 888 KB Output is correct
23 Correct 5 ms 760 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 6 ms 1016 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 6 ms 632 KB Output is correct
30 Correct 5 ms 632 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 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 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 376 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 760 KB Output is correct
17 Correct 6 ms 888 KB Output is correct
18 Correct 7 ms 1016 KB Output is correct
19 Correct 6 ms 1016 KB Output is correct
20 Correct 6 ms 1016 KB Output is correct
21 Correct 6 ms 1144 KB Output is correct
22 Correct 6 ms 888 KB Output is correct
23 Correct 5 ms 760 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 6 ms 1016 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 6 ms 632 KB Output is correct
30 Correct 5 ms 632 KB Output is correct
31 Correct 9 ms 2808 KB Output is correct
32 Correct 13 ms 3448 KB Output is correct
33 Correct 11 ms 3960 KB Output is correct
34 Correct 12 ms 3832 KB Output is correct
35 Correct 14 ms 4728 KB Output is correct
36 Correct 12 ms 4728 KB Output is correct
37 Correct 10 ms 3960 KB Output is correct
38 Correct 9 ms 3192 KB Output is correct
39 Correct 8 ms 888 KB Output is correct
40 Correct 12 ms 4476 KB Output is correct
41 Correct 8 ms 1016 KB Output is correct
42 Correct 9 ms 1656 KB Output is correct
43 Correct 8 ms 888 KB Output is correct
44 Correct 9 ms 2168 KB Output is correct
45 Correct 9 ms 2168 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 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 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 376 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 760 KB Output is correct
17 Correct 6 ms 888 KB Output is correct
18 Correct 7 ms 1016 KB Output is correct
19 Correct 6 ms 1016 KB Output is correct
20 Correct 6 ms 1016 KB Output is correct
21 Correct 6 ms 1144 KB Output is correct
22 Correct 6 ms 888 KB Output is correct
23 Correct 5 ms 760 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 6 ms 1016 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 6 ms 632 KB Output is correct
30 Correct 5 ms 632 KB Output is correct
31 Correct 9 ms 2808 KB Output is correct
32 Correct 13 ms 3448 KB Output is correct
33 Correct 11 ms 3960 KB Output is correct
34 Correct 12 ms 3832 KB Output is correct
35 Correct 14 ms 4728 KB Output is correct
36 Correct 12 ms 4728 KB Output is correct
37 Correct 10 ms 3960 KB Output is correct
38 Correct 9 ms 3192 KB Output is correct
39 Correct 8 ms 888 KB Output is correct
40 Correct 12 ms 4476 KB Output is correct
41 Correct 8 ms 1016 KB Output is correct
42 Correct 9 ms 1656 KB Output is correct
43 Correct 8 ms 888 KB Output is correct
44 Correct 9 ms 2168 KB Output is correct
45 Correct 9 ms 2168 KB Output is correct
46 Correct 131 ms 54884 KB Output is correct
47 Correct 158 ms 62384 KB Output is correct
48 Correct 223 ms 124280 KB Output is correct
49 Correct 236 ms 133752 KB Output is correct
50 Correct 258 ms 148032 KB Output is correct
51 Correct 247 ms 145400 KB Output is correct
52 Correct 124 ms 73084 KB Output is correct
53 Correct 77 ms 44024 KB Output is correct
54 Correct 115 ms 20476 KB Output is correct
55 Correct 251 ms 140664 KB Output is correct
56 Correct 162 ms 65144 KB Output is correct
57 Correct 152 ms 54008 KB Output is correct
58 Correct 177 ms 59512 KB Output is correct
59 Correct 195 ms 84088 KB Output is correct
60 Correct 193 ms 83832 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 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 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 376 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 760 KB Output is correct
17 Correct 6 ms 888 KB Output is correct
18 Correct 7 ms 1016 KB Output is correct
19 Correct 6 ms 1016 KB Output is correct
20 Correct 6 ms 1016 KB Output is correct
21 Correct 6 ms 1144 KB Output is correct
22 Correct 6 ms 888 KB Output is correct
23 Correct 5 ms 760 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 6 ms 1016 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 6 ms 632 KB Output is correct
30 Correct 5 ms 632 KB Output is correct
31 Correct 9 ms 2808 KB Output is correct
32 Correct 13 ms 3448 KB Output is correct
33 Correct 11 ms 3960 KB Output is correct
34 Correct 12 ms 3832 KB Output is correct
35 Correct 14 ms 4728 KB Output is correct
36 Correct 12 ms 4728 KB Output is correct
37 Correct 10 ms 3960 KB Output is correct
38 Correct 9 ms 3192 KB Output is correct
39 Correct 8 ms 888 KB Output is correct
40 Correct 12 ms 4476 KB Output is correct
41 Correct 8 ms 1016 KB Output is correct
42 Correct 9 ms 1656 KB Output is correct
43 Correct 8 ms 888 KB Output is correct
44 Correct 9 ms 2168 KB Output is correct
45 Correct 9 ms 2168 KB Output is correct
46 Correct 131 ms 54884 KB Output is correct
47 Correct 158 ms 62384 KB Output is correct
48 Correct 223 ms 124280 KB Output is correct
49 Correct 236 ms 133752 KB Output is correct
50 Correct 258 ms 148032 KB Output is correct
51 Correct 247 ms 145400 KB Output is correct
52 Correct 124 ms 73084 KB Output is correct
53 Correct 77 ms 44024 KB Output is correct
54 Correct 115 ms 20476 KB Output is correct
55 Correct 251 ms 140664 KB Output is correct
56 Correct 162 ms 65144 KB Output is correct
57 Correct 152 ms 54008 KB Output is correct
58 Correct 177 ms 59512 KB Output is correct
59 Correct 195 ms 84088 KB Output is correct
60 Correct 193 ms 83832 KB Output is correct
61 Correct 608 ms 253280 KB Output is correct
62 Correct 661 ms 244344 KB Output is correct
63 Runtime error 669 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
64 Halted 0 ms 0 KB -