Submission #290782

# Submission time Handle Problem Language Result Execution time Memory
290782 2020-09-04T12:44:05 Z Autoratch Bigger segments (IZhO19_segments) C++14
100 / 100
324 ms 48376 KB
#include <bits/stdc++.h>
using namespace std;

struct node
{
	int sz;
	long long val;
	int prio,id,mx;
	node *l,*r;
};

using pnode = node*;

int sz(pnode t){ if(!t) return 0; return t->sz; }
int id(pnode t){ if(!t) return 0; return t->id; }
int mx(pnode t){ if(!t) return 0; return t->mx; }
void upd(pnode t)
{ 
	if(!t) return; 
	t->sz = sz(t->l)+1+sz(t->r);
	t->mx = max(mx(t->l),mx(t->r));
	t->mx = max(t->mx,t->id);
}

void split(pnode t,pnode &l,pnode &r,int k)
{
	if(!t) return void(l = r = NULL);
	if(k<=sz(t->l)) split(t->l,l,t->l,k),r = t;
	else split(t->r,t->r,r,k-1-sz(t->l)),l = t;
	upd(t);
}

void merge(pnode &t,pnode l,pnode r)
{
	if(!l) return void(t = r);
	if(!r) return void(t = l);
	if(l->prio>r->prio) merge(l->r,l->r,r),t = l;
	else merge(r->l,l,r->l),t = r;
	upd(t);
}

pnode init(long long val,int mx)
{
	pnode res = new node;
	*res = {1,val,rand(),mx,mx,NULL,NULL};
	return res;
}

int count(pnode t,long long x)
{
	if(!t) return 0;
	if(t->val<=x) return 1+sz(t->l)+count(t->r,x);
	else return count(t->l,x);
}

pnode treap;

void insert(long long val,int mx)
{
	pnode res = init(val,mx);
	int cnt = count(treap,val);
	pnode t1,t2;
	split(treap,t1,t2,cnt);
	merge(treap,t1,res);
	merge(treap,treap,t2);
}

int findmx(pnode t,long long val)
{
	if(!t) return 0;
	if(t->val<=val) return max(findmx(t->r,val),max(mx(t->l),t->id));
	else return findmx(t->l,val);
}

void print(pnode t)
{
	if(!t) return;
	print(t->l);
	cout << t->val << ' ' << t->mx << ' ' << t->id << endl;
	print(t->r);
}

const int N = 5e5 + 1;

long long n,s[N],dp[N],mn[N];

int main()
{
	srand(time(NULL));
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n;
	for(int i = 1;i <= n;i++) cin >> s[i],s[i]+=s[i-1];
	for(int i = 1;i <= n;i++)
	{
		int j = findmx(treap,s[i]);
		dp[i] = dp[j]+1,mn[i] = s[i]-s[j];		
		insert(mn[i]+s[i],i);
	}
	cout << dp[n];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 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 640 KB Output is correct
32 Correct 2 ms 640 KB Output is correct
33 Correct 2 ms 640 KB Output is correct
34 Correct 2 ms 640 KB Output is correct
35 Correct 2 ms 640 KB Output is correct
36 Correct 2 ms 640 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 1 ms 512 KB Output is correct
39 Correct 2 ms 640 KB Output is correct
40 Correct 2 ms 640 KB Output is correct
41 Correct 2 ms 640 KB Output is correct
42 Correct 2 ms 640 KB Output is correct
43 Correct 2 ms 640 KB Output is correct
44 Correct 2 ms 640 KB Output is correct
45 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 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 640 KB Output is correct
32 Correct 2 ms 640 KB Output is correct
33 Correct 2 ms 640 KB Output is correct
34 Correct 2 ms 640 KB Output is correct
35 Correct 2 ms 640 KB Output is correct
36 Correct 2 ms 640 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 1 ms 512 KB Output is correct
39 Correct 2 ms 640 KB Output is correct
40 Correct 2 ms 640 KB Output is correct
41 Correct 2 ms 640 KB Output is correct
42 Correct 2 ms 640 KB Output is correct
43 Correct 2 ms 640 KB Output is correct
44 Correct 2 ms 640 KB Output is correct
45 Correct 2 ms 768 KB Output is correct
46 Correct 40 ms 9240 KB Output is correct
47 Correct 66 ms 9464 KB Output is correct
48 Correct 55 ms 9724 KB Output is correct
49 Correct 60 ms 9848 KB Output is correct
50 Correct 57 ms 9976 KB Output is correct
51 Correct 59 ms 9976 KB Output is correct
52 Correct 29 ms 5112 KB Output is correct
53 Correct 16 ms 3200 KB Output is correct
54 Correct 52 ms 9208 KB Output is correct
55 Correct 53 ms 9976 KB Output is correct
56 Correct 44 ms 9464 KB Output is correct
57 Correct 44 ms 9336 KB Output is correct
58 Correct 53 ms 9464 KB Output is correct
59 Correct 48 ms 9592 KB Output is correct
60 Correct 50 ms 9592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 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 640 KB Output is correct
32 Correct 2 ms 640 KB Output is correct
33 Correct 2 ms 640 KB Output is correct
34 Correct 2 ms 640 KB Output is correct
35 Correct 2 ms 640 KB Output is correct
36 Correct 2 ms 640 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 1 ms 512 KB Output is correct
39 Correct 2 ms 640 KB Output is correct
40 Correct 2 ms 640 KB Output is correct
41 Correct 2 ms 640 KB Output is correct
42 Correct 2 ms 640 KB Output is correct
43 Correct 2 ms 640 KB Output is correct
44 Correct 2 ms 640 KB Output is correct
45 Correct 2 ms 768 KB Output is correct
46 Correct 40 ms 9240 KB Output is correct
47 Correct 66 ms 9464 KB Output is correct
48 Correct 55 ms 9724 KB Output is correct
49 Correct 60 ms 9848 KB Output is correct
50 Correct 57 ms 9976 KB Output is correct
51 Correct 59 ms 9976 KB Output is correct
52 Correct 29 ms 5112 KB Output is correct
53 Correct 16 ms 3200 KB Output is correct
54 Correct 52 ms 9208 KB Output is correct
55 Correct 53 ms 9976 KB Output is correct
56 Correct 44 ms 9464 KB Output is correct
57 Correct 44 ms 9336 KB Output is correct
58 Correct 53 ms 9464 KB Output is correct
59 Correct 48 ms 9592 KB Output is correct
60 Correct 50 ms 9592 KB Output is correct
61 Correct 210 ms 45304 KB Output is correct
62 Correct 230 ms 45304 KB Output is correct
63 Correct 324 ms 45944 KB Output is correct
64 Correct 300 ms 47964 KB Output is correct
65 Correct 255 ms 48248 KB Output is correct
66 Correct 303 ms 48340 KB Output is correct
67 Correct 246 ms 38648 KB Output is correct
68 Correct 118 ms 19448 KB Output is correct
69 Correct 295 ms 44412 KB Output is correct
70 Correct 274 ms 48376 KB Output is correct
71 Correct 242 ms 45560 KB Output is correct
72 Correct 268 ms 45672 KB Output is correct
73 Correct 273 ms 46328 KB Output is correct
74 Correct 280 ms 46712 KB Output is correct
75 Correct 283 ms 46712 KB Output is correct