답안 #287976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287976 2020-09-01T07:23:15 Z dvdg6566 Bigger segments (IZhO19_segments) C++14
100 / 100
772 ms 58884 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define f first
#define s second
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()
#define lb lower_bound
#define ub upper_bound
const ll MAXN=500001;
const ll MOD=1e9+7;
const ll INF = 3e9;

ll A[MAXN];
ll N;

struct node{
	node *l,*r;
	pi v;
	node(){
		v=mp(0,0);
		l=r=nullptr;
	}
	pi ask(ll s,ll e,ll x,ll y){
		ll m=(s+e)/2;
		assert(s<=x&&y<=e);
		if(s==x&&e==y)return v;
		pi t=mp(0,0);
		if(l&&x<=m)t=max(t, l->ask(s,m,x,min(y,m)));
		if(r&&y>m)t=max(t,r->ask(m+1,e,max(m+1,x),y));
		return t;
	}
	void up(ll s,ll e,ll x,pi va){
		ll m=(s+e)/2;
		assert(s<=x&&x<=e);
		if(s==e){v=max(v,va);return;}
		if(x<=m){
			if(!l)l=new node();
			l->up(s,m,x,va);
		}else{
			if(!r)r=new node();
			r->up(m+1,e,x,va);
		}
		v=mp(0,0);
		if(l)v=max(v,l->v);
		if(r)v=max(v,r->v);
	}
}*root;

int main(){
	cin>>N;
	for(int i=1;i<=N;++i){
		cin>>A[i];
		A[i]+=A[i-1];
	}
	vi des;
	for(int i=0;i<=N;++i){
		des.pb(A[i]);
	}
	des.pb(1e18);
	sort(ALL(des));
	des.resize(unique(ALL(des)) - des.begin());

	root=new node();
	for(int i=1;i<=N;++i){
		ll tar=lb(ALL(des),A[i])-des.begin();
		pi x=root->ask(0,SZ(des)-1,0,tar);
		ll p=x.s;
		if(i==N){
			cout<<x.f+1;
			return 0;
		}
		ll xval=2*A[i]-A[p];
		ll pos=lb(ALL(des),xval)-des.begin();
		root->up(0,SZ(des)-1,pos, mp(x.f+1,i));
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
33 Correct 4 ms 640 KB Output is correct
34 Correct 4 ms 512 KB Output is correct
35 Correct 5 ms 672 KB Output is correct
36 Correct 5 ms 640 KB Output is correct
37 Correct 4 ms 516 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 4 ms 640 KB Output is correct
41 Correct 3 ms 672 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 640 KB Output is correct
44 Correct 3 ms 640 KB Output is correct
45 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
33 Correct 4 ms 640 KB Output is correct
34 Correct 4 ms 512 KB Output is correct
35 Correct 5 ms 672 KB Output is correct
36 Correct 5 ms 640 KB Output is correct
37 Correct 4 ms 516 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 4 ms 640 KB Output is correct
41 Correct 3 ms 672 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 640 KB Output is correct
44 Correct 3 ms 640 KB Output is correct
45 Correct 3 ms 640 KB Output is correct
46 Correct 65 ms 2672 KB Output is correct
47 Correct 101 ms 7144 KB Output is correct
48 Correct 131 ms 9064 KB Output is correct
49 Correct 147 ms 11244 KB Output is correct
50 Correct 146 ms 12012 KB Output is correct
51 Correct 146 ms 9864 KB Output is correct
52 Correct 71 ms 5232 KB Output is correct
53 Correct 42 ms 3188 KB Output is correct
54 Correct 87 ms 8812 KB Output is correct
55 Correct 149 ms 11368 KB Output is correct
56 Correct 108 ms 11752 KB Output is correct
57 Correct 88 ms 7788 KB Output is correct
58 Correct 100 ms 9584 KB Output is correct
59 Correct 118 ms 11756 KB Output is correct
60 Correct 134 ms 11756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
33 Correct 4 ms 640 KB Output is correct
34 Correct 4 ms 512 KB Output is correct
35 Correct 5 ms 672 KB Output is correct
36 Correct 5 ms 640 KB Output is correct
37 Correct 4 ms 516 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 4 ms 640 KB Output is correct
41 Correct 3 ms 672 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 640 KB Output is correct
44 Correct 3 ms 640 KB Output is correct
45 Correct 3 ms 640 KB Output is correct
46 Correct 65 ms 2672 KB Output is correct
47 Correct 101 ms 7144 KB Output is correct
48 Correct 131 ms 9064 KB Output is correct
49 Correct 147 ms 11244 KB Output is correct
50 Correct 146 ms 12012 KB Output is correct
51 Correct 146 ms 9864 KB Output is correct
52 Correct 71 ms 5232 KB Output is correct
53 Correct 42 ms 3188 KB Output is correct
54 Correct 87 ms 8812 KB Output is correct
55 Correct 149 ms 11368 KB Output is correct
56 Correct 108 ms 11752 KB Output is correct
57 Correct 88 ms 7788 KB Output is correct
58 Correct 100 ms 9584 KB Output is correct
59 Correct 118 ms 11756 KB Output is correct
60 Correct 134 ms 11756 KB Output is correct
61 Correct 326 ms 9632 KB Output is correct
62 Correct 419 ms 20828 KB Output is correct
63 Correct 532 ms 34688 KB Output is correct
64 Correct 740 ms 51292 KB Output is correct
65 Correct 764 ms 58884 KB Output is correct
66 Correct 760 ms 47836 KB Output is correct
67 Correct 595 ms 39132 KB Output is correct
68 Correct 294 ms 19844 KB Output is correct
69 Correct 481 ms 42716 KB Output is correct
70 Correct 772 ms 55640 KB Output is correct
71 Correct 562 ms 57172 KB Output is correct
72 Correct 498 ms 38800 KB Output is correct
73 Correct 593 ms 51036 KB Output is correct
74 Correct 652 ms 58376 KB Output is correct
75 Correct 658 ms 58464 KB Output is correct