Submission #719530

#TimeUsernameProblemLanguageResultExecution timeMemory
719530thimote75Horses (IOI15_horses)C++14
17 / 100
366 ms62332 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...