Submission #201337

# Submission time Handle Problem Language Result Execution time Memory
201337 2020-02-10T08:30:32 Z guangxuan Bigger segments (IZhO19_segments) C++14
73 / 100
1500 ms 142052 KB
#include <bits/stdc++.h>

using namespace std;

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

pair<int,long long> query(long long x){
	pair<int,long long> ans = {-1,-1};
	for(x++;x;x-=x&(-x)){
		if(fw.find(x)==fw.end())continue;
		ans = max(ans,fw[x]);
	}
	return ans;
}

void up(long long x,pair<int,long long> v ){
	for(x++;x<1e15;x+=x&(-x)){
		if(fw.find(x)==fw.end())fw[x] = v;
		else fw[x] = max(fw[x],v);
	}
}

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];
	}
	up(0,{0,0});
	for(int i=1;i<=n;i++){
		pair<int,long long> res = query(rs[i]); 
		dp[i] = {res.first,res.second - rs[i]};
		dp[i].first++;
		up(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:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
segments.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory 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 4 ms 380 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 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
# Verdict Execution time Memory 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 4 ms 380 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 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 636 KB Output is correct
17 Correct 6 ms 632 KB Output is correct
18 Correct 7 ms 760 KB Output is correct
19 Correct 7 ms 760 KB Output is correct
20 Correct 6 ms 764 KB Output is correct
21 Correct 7 ms 760 KB Output is correct
22 Correct 6 ms 632 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 8 ms 760 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 6 ms 504 KB Output is correct
30 Correct 8 ms 504 KB Output is correct
# Verdict Execution time Memory 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 4 ms 380 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 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 636 KB Output is correct
17 Correct 6 ms 632 KB Output is correct
18 Correct 7 ms 760 KB Output is correct
19 Correct 7 ms 760 KB Output is correct
20 Correct 6 ms 764 KB Output is correct
21 Correct 7 ms 760 KB Output is correct
22 Correct 6 ms 632 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 8 ms 760 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 6 ms 504 KB Output is correct
30 Correct 8 ms 504 KB Output is correct
31 Correct 16 ms 2296 KB Output is correct
32 Correct 16 ms 2344 KB Output is correct
33 Correct 17 ms 2728 KB Output is correct
34 Correct 16 ms 2600 KB Output is correct
35 Correct 18 ms 3368 KB Output is correct
36 Correct 17 ms 2984 KB Output is correct
37 Correct 15 ms 2600 KB Output is correct
38 Correct 13 ms 2296 KB Output is correct
39 Correct 13 ms 760 KB Output is correct
40 Correct 17 ms 2856 KB Output is correct
41 Correct 12 ms 760 KB Output is correct
42 Correct 12 ms 1016 KB Output is correct
43 Correct 12 ms 760 KB Output is correct
44 Correct 13 ms 1528 KB Output is correct
45 Correct 14 ms 1528 KB Output is correct
# Verdict Execution time Memory 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 4 ms 380 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 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 636 KB Output is correct
17 Correct 6 ms 632 KB Output is correct
18 Correct 7 ms 760 KB Output is correct
19 Correct 7 ms 760 KB Output is correct
20 Correct 6 ms 764 KB Output is correct
21 Correct 7 ms 760 KB Output is correct
22 Correct 6 ms 632 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 8 ms 760 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 6 ms 504 KB Output is correct
30 Correct 8 ms 504 KB Output is correct
31 Correct 16 ms 2296 KB Output is correct
32 Correct 16 ms 2344 KB Output is correct
33 Correct 17 ms 2728 KB Output is correct
34 Correct 16 ms 2600 KB Output is correct
35 Correct 18 ms 3368 KB Output is correct
36 Correct 17 ms 2984 KB Output is correct
37 Correct 15 ms 2600 KB Output is correct
38 Correct 13 ms 2296 KB Output is correct
39 Correct 13 ms 760 KB Output is correct
40 Correct 17 ms 2856 KB Output is correct
41 Correct 12 ms 760 KB Output is correct
42 Correct 12 ms 1016 KB Output is correct
43 Correct 12 ms 760 KB Output is correct
44 Correct 13 ms 1528 KB Output is correct
45 Correct 14 ms 1528 KB Output is correct
46 Correct 465 ms 38252 KB Output is correct
47 Correct 554 ms 43756 KB Output is correct
48 Correct 1025 ms 81388 KB Output is correct
49 Correct 1059 ms 85772 KB Output is correct
50 Correct 1154 ms 95316 KB Output is correct
51 Correct 1121 ms 89168 KB Output is correct
52 Correct 507 ms 44712 KB Output is correct
53 Correct 308 ms 32904 KB Output is correct
54 Correct 244 ms 13500 KB Output is correct
55 Correct 1094 ms 87024 KB Output is correct
56 Correct 514 ms 41324 KB Output is correct
57 Correct 469 ms 34840 KB Output is correct
58 Correct 515 ms 38764 KB Output is correct
59 Correct 629 ms 50844 KB Output is correct
60 Correct 645 ms 50668 KB Output is correct
# Verdict Execution time Memory 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 4 ms 380 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 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 636 KB Output is correct
17 Correct 6 ms 632 KB Output is correct
18 Correct 7 ms 760 KB Output is correct
19 Correct 7 ms 760 KB Output is correct
20 Correct 6 ms 764 KB Output is correct
21 Correct 7 ms 760 KB Output is correct
22 Correct 6 ms 632 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 8 ms 760 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 6 ms 504 KB Output is correct
30 Correct 8 ms 504 KB Output is correct
31 Correct 16 ms 2296 KB Output is correct
32 Correct 16 ms 2344 KB Output is correct
33 Correct 17 ms 2728 KB Output is correct
34 Correct 16 ms 2600 KB Output is correct
35 Correct 18 ms 3368 KB Output is correct
36 Correct 17 ms 2984 KB Output is correct
37 Correct 15 ms 2600 KB Output is correct
38 Correct 13 ms 2296 KB Output is correct
39 Correct 13 ms 760 KB Output is correct
40 Correct 17 ms 2856 KB Output is correct
41 Correct 12 ms 760 KB Output is correct
42 Correct 12 ms 1016 KB Output is correct
43 Correct 12 ms 760 KB Output is correct
44 Correct 13 ms 1528 KB Output is correct
45 Correct 14 ms 1528 KB Output is correct
46 Correct 465 ms 38252 KB Output is correct
47 Correct 554 ms 43756 KB Output is correct
48 Correct 1025 ms 81388 KB Output is correct
49 Correct 1059 ms 85772 KB Output is correct
50 Correct 1154 ms 95316 KB Output is correct
51 Correct 1121 ms 89168 KB Output is correct
52 Correct 507 ms 44712 KB Output is correct
53 Correct 308 ms 32904 KB Output is correct
54 Correct 244 ms 13500 KB Output is correct
55 Correct 1094 ms 87024 KB Output is correct
56 Correct 514 ms 41324 KB Output is correct
57 Correct 469 ms 34840 KB Output is correct
58 Correct 515 ms 38764 KB Output is correct
59 Correct 629 ms 50844 KB Output is correct
60 Correct 645 ms 50668 KB Output is correct
61 Execution timed out 1574 ms 142052 KB Time limit exceeded
62 Halted 0 ms 0 KB -