Submission #91995

# Submission time Handle Problem Language Result Execution time Memory
91995 2018-12-31T19:29:01 Z luciocf Horses (IOI15_horses) C++14
100 / 100
214 ms 58508 KB
#include <bits/stdc++.h>
#include "horses.h"

using namespace std;

const int maxn = 5e5+10;

const int mod = 1e9+7;

typedef long long ll;

ll x[maxn], y[maxn];

int n;

struct node
{
	double maior, soma;
	ll maiorp, prod;
} tree[4*maxn];

void join(int node)
{
	tree[node].maior = max(tree[2*node].maior, tree[2*node].soma+tree[2*node+1].maior);
	tree[node].soma = tree[2*node].soma+tree[2*node+1].soma;

	if (tree[2*node].maior > tree[2*node].soma+tree[2*node+1].maior)
		tree[node].maiorp = tree[2*node].maiorp;
	else 
		tree[node].maiorp = (tree[2*node].prod*tree[2*node+1].maiorp)%mod;

	tree[node].prod = (tree[2*node].prod*tree[2*node+1].prod)%mod;
}

void build(int node, int l, int r)
{
	if (l == r)
	{
		tree[node].maior = log2(x[l])+log2(y[l]);
		tree[node].soma = log2(x[l]);

		tree[node].maiorp = (x[l]*y[l])%mod;
		tree[node].prod = x[l]%mod;

		return;
	}

	int mid = (l+r)>>1;

	build(2*node, l, mid); build(2*node+1, mid+1, r);
	join(node);
}

void upd(int node, int l, int r, int pos)
{
	if (l == r)
	{
		tree[node].maior = log2(x[l])+log2(y[l]);
		tree[node].soma = log2(x[l]);

		tree[node].maiorp = (x[l]*y[l])%mod;
		tree[node].prod = x[l]%mod;	

		return;
	}

	int mid = (l+r)>>1;

	if (pos <= mid) upd(2*node, l, mid, pos);
	else upd(2*node+1, mid+1, r, pos);

	join(node);
}

int init(int N, int X[], int Y[])
{
	n = N;
	for (int i = 0; i < n; i++)
		x[i] = (ll)X[i], y[i] = (ll)Y[i];
	build(1, 0, n-1);

	return (int)tree[1].maiorp;
}

int updateX(int pos, int val)
{
	x[pos] = (ll)val;
	upd(1, 0, n-1, pos);

	return (int)tree[1].maiorp;
}

int updateY(int pos, int val)
{
	y[pos] = (ll)val;
	upd(1, 0, n-1, pos);

	return (int)tree[1].maiorp;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 508 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2 ms 508 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 2 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 45816 KB Output is correct
2 Correct 190 ms 58508 KB Output is correct
3 Correct 176 ms 49656 KB Output is correct
4 Correct 169 ms 53612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 380 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 89 ms 48888 KB Output is correct
34 Correct 88 ms 49016 KB Output is correct
35 Correct 102 ms 55928 KB Output is correct
36 Correct 100 ms 55820 KB Output is correct
37 Correct 62 ms 47096 KB Output is correct
38 Correct 69 ms 47992 KB Output is correct
39 Correct 57 ms 47096 KB Output is correct
40 Correct 81 ms 50936 KB Output is correct
41 Correct 60 ms 46984 KB Output is correct
42 Correct 60 ms 47096 KB Output is correct
43 Correct 79 ms 51316 KB Output is correct
44 Correct 82 ms 51320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 472 KB Output is correct
32 Correct 2 ms 508 KB Output is correct
33 Correct 97 ms 49736 KB Output is correct
34 Correct 214 ms 58488 KB Output is correct
35 Correct 170 ms 49656 KB Output is correct
36 Correct 199 ms 53436 KB Output is correct
37 Correct 85 ms 48936 KB Output is correct
38 Correct 83 ms 49020 KB Output is correct
39 Correct 106 ms 55956 KB Output is correct
40 Correct 104 ms 55800 KB Output is correct
41 Correct 70 ms 47196 KB Output is correct
42 Correct 75 ms 47960 KB Output is correct
43 Correct 63 ms 46968 KB Output is correct
44 Correct 87 ms 50936 KB Output is correct
45 Correct 65 ms 47064 KB Output is correct
46 Correct 63 ms 47096 KB Output is correct
47 Correct 81 ms 51320 KB Output is correct
48 Correct 82 ms 51320 KB Output is correct
49 Correct 196 ms 51068 KB Output is correct
50 Correct 187 ms 51088 KB Output is correct
51 Correct 128 ms 57848 KB Output is correct
52 Correct 127 ms 57228 KB Output is correct
53 Correct 149 ms 49272 KB Output is correct
54 Correct 110 ms 49848 KB Output is correct
55 Correct 90 ms 48012 KB Output is correct
56 Correct 117 ms 52728 KB Output is correct
57 Correct 94 ms 48632 KB Output is correct
58 Correct 88 ms 49144 KB Output is correct
59 Correct 83 ms 51320 KB Output is correct