답안 #384600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384600 2021-04-01T21:37:20 Z dorijanlendvaj Bigger segments (IZhO19_segments) C++14
100 / 100
274 ms 26988 KB
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
using namespace std;
using ll=long long;
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)

const int N=500010,MOD=1e9+7,M=1<<19;
const char en='\n';
const ll LLINF=1ll<<60;
int t,n,h[N];
ll pr[N];
pll seg[M*2+10];

void upd(int i,pll x)
{
	seg[i+=M]=x;
	for (i/=2;i;i/=2) seg[i]=max(seg[i*2],seg[i*2+1]);
}

pll ge(int l,int r,int lo=0,int hi=M,int i=1)
{
	if (lo>=l && hi<=r) return seg[i];
	if (lo>=r || hi<=l) return {0,0};
	int mid=(lo+hi)/2;
	return max(ge(l,r,lo,mid,i*2),ge(l,r,mid,hi,i*2+1));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for (int i=0;i<n;++i)
	{
		cin>>h[i];
		pr[i+1]=pr[i]+h[i];
	}
	for (int i=1;i<=n;++i)
	{
		pll re=ge(0,i);
		if (i==n)
		{
			cout<<re.x+1<<en;
			exit(0);
		}
		//cout<<re.x<<' '<<re.y<<en;
		ll su=pr[i]-re.y;
		int po=lower_bound(pr+1,pr+n+1,pr[i]+su)-pr-1;
		upd(po,{re.x+1,pr[i]});
	}
}





# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 492 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 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 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 364 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 364 KB Output is correct
3 Correct 2 ms 492 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 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 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 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 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 492 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 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 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 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 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 3 ms 492 KB Output is correct
35 Correct 3 ms 620 KB Output is correct
36 Correct 3 ms 620 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 3 ms 620 KB Output is correct
39 Correct 2 ms 492 KB Output is correct
40 Correct 3 ms 620 KB Output is correct
41 Correct 3 ms 492 KB Output is correct
42 Correct 3 ms 492 KB Output is correct
43 Correct 3 ms 492 KB Output is correct
44 Correct 3 ms 572 KB Output is correct
45 Correct 4 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 492 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 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 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 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 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 3 ms 492 KB Output is correct
35 Correct 3 ms 620 KB Output is correct
36 Correct 3 ms 620 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 3 ms 620 KB Output is correct
39 Correct 2 ms 492 KB Output is correct
40 Correct 3 ms 620 KB Output is correct
41 Correct 3 ms 492 KB Output is correct
42 Correct 3 ms 492 KB Output is correct
43 Correct 3 ms 492 KB Output is correct
44 Correct 3 ms 572 KB Output is correct
45 Correct 4 ms 620 KB Output is correct
46 Correct 43 ms 2028 KB Output is correct
47 Correct 48 ms 4588 KB Output is correct
48 Correct 60 ms 5484 KB Output is correct
49 Correct 58 ms 5356 KB Output is correct
50 Correct 61 ms 5740 KB Output is correct
51 Correct 61 ms 5740 KB Output is correct
52 Correct 28 ms 3052 KB Output is correct
53 Correct 17 ms 2028 KB Output is correct
54 Correct 48 ms 4972 KB Output is correct
55 Correct 54 ms 5740 KB Output is correct
56 Correct 51 ms 5228 KB Output is correct
57 Correct 46 ms 3836 KB Output is correct
58 Correct 48 ms 4588 KB Output is correct
59 Correct 53 ms 5228 KB Output is correct
60 Correct 52 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 492 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 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 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 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 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 3 ms 492 KB Output is correct
35 Correct 3 ms 620 KB Output is correct
36 Correct 3 ms 620 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 3 ms 620 KB Output is correct
39 Correct 2 ms 492 KB Output is correct
40 Correct 3 ms 620 KB Output is correct
41 Correct 3 ms 492 KB Output is correct
42 Correct 3 ms 492 KB Output is correct
43 Correct 3 ms 492 KB Output is correct
44 Correct 3 ms 572 KB Output is correct
45 Correct 4 ms 620 KB Output is correct
46 Correct 43 ms 2028 KB Output is correct
47 Correct 48 ms 4588 KB Output is correct
48 Correct 60 ms 5484 KB Output is correct
49 Correct 58 ms 5356 KB Output is correct
50 Correct 61 ms 5740 KB Output is correct
51 Correct 61 ms 5740 KB Output is correct
52 Correct 28 ms 3052 KB Output is correct
53 Correct 17 ms 2028 KB Output is correct
54 Correct 48 ms 4972 KB Output is correct
55 Correct 54 ms 5740 KB Output is correct
56 Correct 51 ms 5228 KB Output is correct
57 Correct 46 ms 3836 KB Output is correct
58 Correct 48 ms 4588 KB Output is correct
59 Correct 53 ms 5228 KB Output is correct
60 Correct 52 ms 5228 KB Output is correct
61 Correct 203 ms 8428 KB Output is correct
62 Correct 211 ms 16108 KB Output is correct
63 Correct 248 ms 19948 KB Output is correct
64 Correct 274 ms 26476 KB Output is correct
65 Correct 267 ms 26988 KB Output is correct
66 Correct 268 ms 26860 KB Output is correct
67 Correct 215 ms 21484 KB Output is correct
68 Correct 107 ms 10988 KB Output is correct
69 Correct 239 ms 22892 KB Output is correct
70 Correct 269 ms 26860 KB Output is correct
71 Correct 246 ms 23916 KB Output is correct
72 Correct 234 ms 18028 KB Output is correct
73 Correct 248 ms 22508 KB Output is correct
74 Correct 254 ms 25196 KB Output is correct
75 Correct 256 ms 25196 KB Output is correct