#include "horses.h"
using namespace std;
#define lpos pos*2
#define rpos pos*2+1
const int MOD = 1e9 + 7;
const int SIZE = 5e5 + 5;
struct Node {
int pro = 1;
long double sum = 0, mx = 0;
Node operator + (const Node& rhs) const {
Node re;
re.pro = 1ll * pro * rhs.pro % MOD;
re.sum = sum + rhs.sum;
re.mx = max(mx, sum + rhs.mx);
return re;
}
} node[4 * SIZE];
int n, y[SIZE];
void upd(int pos, int l, int r, int p, int ty, int x) {
if (l == r) {
if (ty == 1) {
node[pos].pro = x;
node[pos].sum = log((long double) x);
}
if (ty == 2) {
node[pos].mx = node[pos].sum + log((long double) (y[p] = x));
}
return;
}
int mid = (l + r) / 2;
if (p <= mid) upd(lpos, l, mid, p, ty, x);
else upd(rpos, mid + 1, r, p, ty, x);
node[pos] = node[lpos] + node[rpos];
}
int que(int pos, int l, int r, int cur = 1) {
if (l == r) return 1ll * cur * node[pos].pro % MOD * y[l] % MOD;
int mid = (l + r) / 2;
if (node[lpos].mx >= node[lpos].sum + node[rpos].mx) return que(lpos, l, mid, cur);
else return que(rpos, mid + 1, r, 1ll * cur * node[lpos].pro % MOD);
}
void build(int pos, int l, int r, int X[], int Y[]) {
if (l == r) {
node[pos].pro = X[l];
node[pos].sum = log((long double) X[l]);
node[pos].mx = node[pos].sum + log((long double) (y[l] = Y[l]));
return;
}
int mid = (l + r) / 2;
build(lpos, l, mid, X, Y);
build(rpos, mid + 1, r, X, Y);
node[pos] = node[lpos] + node[rpos];
}
int init(int N, int X[], int Y[]) {
n = N;
build(1, 0, n - 1, X, Y);
return que(1, 0, n - 1);
}
int updateX(int pos, int val) {
upd(1, 0, n - 1, pos, 1, val);
return que(1, 0, n - 1);
}
int updateY(int pos, int val) {
upd(1, 0, n - 1, pos, 2, val);
return que(1, 0, n - 1);
}
Compilation message
horses.cpp: In member function 'Node Node::operator+(const Node&) const':
horses.cpp:15:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
15 | re.pro = 1ll * pro * rhs.pro % MOD;
| ~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:17:17: error: 'max' was not declared in this scope; did you mean 'mx'?
17 | re.mx = max(mx, sum + rhs.mx);
| ^~~
| mx
horses.cpp: In function 'void upd(int, int, int, int, int, int)':
horses.cpp:28:29: error: 'log' was not declared in this scope; did you mean 'long'?
28 | node[pos].sum = log((long double) x);
| ^~~
| long
horses.cpp:31:44: error: 'log' was not declared in this scope; did you mean 'long'?
31 | node[pos].mx = node[pos].sum + log((long double) (y[p] = x));
| ^~~
| long
horses.cpp: In function 'int que(int, int, int, int)':
horses.cpp:42:63: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
42 | if (l == r) return 1ll * cur * node[pos].pro % MOD * y[l] % MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:45:66: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
45 | else return que(rpos, mid + 1, r, 1ll * cur * node[lpos].pro % MOD);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void build(int, int, int, int*, int*)':
horses.cpp:51:25: error: 'log' was not declared in this scope; did you mean 'long'?
51 | node[pos].sum = log((long double) X[l]);
| ^~~
| long