Submission #719530

# Submission time Handle Problem Language Result Execution time Memory
719530 2023-04-06T09:09:36 Z thimote75 Horses (IOI15_horses) C++14
17 / 100
366 ms 62332 KB
#include "horses.h"

#include <bits/stdc++.h>
using namespace std;

#define ld long double
#define num long long
#define inf 1e9

const num MOD = 1e9 + 7;

vector<num> X;
vector<num> Y;

struct SGD {
	ld mx_ls = - inf;
	ld se_ls = - inf;

	num mx_pv = 0;
	num se_pv = 0;

	void merge (SGD &l, SGD &r) {
		se_ls = l.se_ls + r.se_ls;
		se_pv = (l.se_pv * r.se_pv) % MOD;

		mx_ls = max(l.mx_ls, r.mx_ls + l.se_ls);

		if (mx_ls == l.mx_ls) mx_pv = l.mx_pv;
		else mx_pv = (l.se_pv * r.mx_pv) % MOD;
	}
};

struct SegTree {
	int size, start, height;
	vector<SGD> tree;

	SegTree (int _size) {
		size = _size;
		height = ceil(log2(size));
		start = 1 << height;

		tree.resize(start << 1);
	}
	num query () {
		return tree[1].mx_pv;
	}
	void _update (int index) {
		if (index == 0) return ;

		if (index < start) {
			int n0 = index << 1;
			int n1 = n0 + 1;

			tree[index].merge(tree[n0], tree[n1]);
		}

		_update(index >> 1);
	}
	void update (int pos, int x, int y) {
		pos += start;

		tree[pos].se_ls = log((ld) x);
		tree[pos].mx_ls = log((ld) x) + log((ld) y);

		tree[pos].se_pv = x;
		tree[pos].mx_pv = (x * y) % MOD;

		_update(pos);
	}
};

SegTree tree(1);
int compute () {
	return max(1, (int) tree.query());
}

int init(int N, int _X[], int _Y[]) {
	X.resize(N);
	Y.resize(N);

	tree = SegTree(N);

	for (int i = 0; i < N; i ++) {
		X [i] = _X[i];
		Y [i] = _Y[i];

		tree.update(i, X[i], Y[i]);
	}

	return compute();
}

int updateX(int i, int val) {
	X [i] = val;
	tree.update(i, X[i], Y[i]);
	return compute();
}

int updateY(int i, int val) {
	Y [i] = val;
	tree.update(i, X[i], Y[i]);
	return compute();
}

Compilation message

horses.cpp: In constructor 'SegTree::SegTree(int)':
horses.cpp:39:16: warning: conversion from 'double' to 'int' may change value [-Wfloat-conversion]
   39 |   height = ceil(log2(size));
      |            ~~~~^~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:87:28: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   87 |   tree.update(i, X[i], Y[i]);
      |                            ^
horses.cpp:87:28: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:95:27: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   95 |  tree.update(i, X[i], Y[i]);
      |                           ^
horses.cpp:95:27: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:101:27: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  101 |  tree.update(i, X[i], Y[i]);
      |                           ^
horses.cpp:101:27: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 325 ms 62332 KB Output is correct
2 Incorrect 366 ms 61420 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -