Submission #719459

# Submission time Handle Problem Language Result Execution time Memory
719459 2023-04-05T23:14:42 Z thimote75 Horses (IOI15_horses) C++14
17 / 100
271 ms 45768 KB
#include "horses.h"

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

#define ld long double
#define num long long

const num MOD = 1e9 + 7;

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

struct SGD {
	double mx_ls = 0;
	double se_ls = 0;

	num mx_pv = 1;
	num se_pv = 1;

	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:38:16: warning: conversion from 'double' to 'int' may change value [-Wfloat-conversion]
   38 |   height = ceil(log2(size));
      |            ~~~~^~~~~~~~~~~~
horses.cpp: In member function 'void SegTree::update(int, int, int)':
horses.cpp:61:24: warning: conversion from 'long double' to 'double' may change value [-Wfloat-conversion]
   61 |   tree[pos].se_ls = log((ld) x);
      |                     ~~~^~~~~~~~
horses.cpp:62:33: warning: conversion from 'long double' to 'double' may change value [-Wfloat-conversion]
   62 |   tree[pos].mx_ls = log((ld) x) + log((ld) y);
      |                     ~~~~~~~~~~~~^~~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:86: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]
   86 |   tree.update(i, X[i], Y[i]);
      |                            ^
horses.cpp:86: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:94: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]
   94 |  tree.update(i, X[i], Y[i]);
      |                           ^
horses.cpp:94: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:100: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]
  100 |  tree.update(i, X[i], Y[i]);
      |                           ^
horses.cpp:100: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 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 0 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
# 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 0 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 0 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 -
# Verdict Execution time Memory Grader output
1 Correct 227 ms 45768 KB Output is correct
2 Incorrect 271 ms 45004 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 0 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 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 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 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 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 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 -