#include "horses.h"
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
int n;
struct node{
ll v, x, y; double dx, dy, dv;
}t[4 * 500005];
node merge(node a, node b){
node res;
b.dx += a.dx, b.dv += a.dx;
if (a.dv > b.dv) res.v = a.v, res.dv = a.dv;
else res.v = a.x * b.v % mod, res.dv = b.dv;
res.x = a.x * b.x % mod;
res.dx = b.dx;
return res;
}
node upd(int i, int l, int r, int ps, ll vx, ll vy){
if (l > ps || r < ps) return t[x];
if (l == r && l == ps) {
node& nd = t[x];
if (vx) nd.dx = log(vx), nd.x = vx;
if (vy) nd.dy = log(vy), nd.y = vy;
nd.v = nd.x * nd.y % mod, nd.dv = nd.dx + nd.dy;
return nd;
}
int m = (l + r) / 2;
return t[i] = merge(upd(i * 2, l, mid, ps, vx, vy), upd(i * 2 + 1, mid + 1, r, ps, vx, vy));
}
int init(int N, int X[], int Y[]) {
n = N;
for (int i = 0; i < N; i++) upd(1, 0, n - 1, i, X[i], Y[i]);
return t[1].v;
}
int updateX(int pos, int val) {
upd(1, 0, n - 1, pos, val, 0);
return t[1].v;
}
int updateY(int pos, int val) {
upd(1, 0, n - 1, pos, 0, val);
return t[1].v;
}
Compilation message
horses.cpp: In function 'node upd(int, int, int, int, ll, ll)':
horses.cpp:25:34: error: 'x' was not declared in this scope
25 | if (l > ps || r < ps) return t[x];
| ^
horses.cpp:27:16: error: 'x' was not declared in this scope
27 | node& nd = t[x];
| ^
horses.cpp:34:36: error: 'mid' was not declared in this scope; did you mean 'mod'?
34 | return t[i] = merge(upd(i * 2, l, mid, ps, vx, vy), upd(i * 2 + 1, mid + 1, r, ps, vx, vy));
| ^~~
| mod
horses.cpp:33:6: warning: unused variable 'm' [-Wunused-variable]
33 | int m = (l + r) / 2;
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:40:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
40 | return t[1].v;
| ~~~~~^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:45:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
45 | return t[1].v;
| ~~~~~^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:50:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
50 | return t[1].v;
| ~~~~~^