#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
using ll = long long;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASKI(i) (1LL << (i))
set <ll> bigX;
const ll MAXN = 5e5+100;
const ll MOD = 1e9 + 7;
ll n;
set <ll> s;
ll calc_mid(ll l, ll r) {
return (l + r) >> 2;
}
namespace X {
ll tree[MAXN*4];
ll a[MAXN];
void build(ll v, ll tl, ll tr) {
if (tl == tr) {
tree[v] = a[tl];
} else {
ll mid = calc_mid(tl, tr);
build(v<<1, tl, mid);
build(v<<1|1,mid+1,tr);
tree[v] = tree[v<<1] * tree[v<<1|1] % MOD;
}
}
void update(ll v, ll tl, ll tr, ll pos) {
if (tl > pos || tr < pos) return;
if (tl == tr) {
tree[v] = a[tl];
return;
}
ll mid = calc_mid(tl, tr);
update(v<<1,tl,mid,pos);
update(v<<1|1,mid+1,tr,pos);
tree[v] = tree[v<<1] * tree[v<<1|1] % MOD;
}
ll query(ll v, ll tl, ll tr, ll pos) {
if (pos < tl) return 1;
if (pos > tr) return tree[v];
ll mid = calc_mid(tl, tr);
return query(v<<1, tl, mid, pos) * query(v<<1|1, mid+1, tr, pos) % MOD;
}
void init(ll X[]) {
for(ll i=0; i<n; i++) a[i] = X[i];
for (ll i=0; i<n; i++) {
if (a[i] > 1) s.insert(i);
}
build(1, 0, n-1);
}
void update(ll pos, ll val) {
s.erase(pos);
a[pos] = val;
if (val >1) s.insert(pos);
update(1,0,n-1,pos);
}
ll query(ll pos) {
return query(1, 0, n-1, pos);
}
}
namespace Y {
ll a[MAXN];
ll tree[MAXN*4];
ll better(ll x, ll y) {
if (x==-1) return y;
if (y==-1) return x;
if (a[x] > a[y]) return x;
return y;
}
void build(ll v, ll tl, ll tr) {
if (tl == tr) tree[v]=tl;
else {
ll mid = calc_mid(tl, tr);
build(v<<1, tl, mid);
build(v<<1|1, mid+1, tr);
tree[v] = better(tree[v<<1], tree[v<<1|1]);
}
}
void update(ll v, ll tl, ll tr, ll pos) {
if (tl > v || tr < v) return;
if (tl == tr) return;
ll mid = calc_mid(tl, tr);
update(v<<1, tl, mid, pos);
update(v<<1|1, mid+1, tr, pos);
tree[v] = better(tree[v<<1], tree[v<<1|1]);
}
ll query(ll v, ll tl1, ll tr1, ll tl2, ll tr2) {
if (tl1 > tr2 || tl2 > tr1) return -1;
if (tl2 <= tl1 && tr2 >= tr1) return tree[v];
ll mid = calc_mid(tl1, tr1);
return better(
query(v<<1,tl1, mid, tl2, tr2),
query(v<<1|1,mid+1, tr1, tl2, tr2)
);
}
void init(ll Y[]) {
for (ll i=0; i< n; i++) a[i] = Y[i];
build(1,0,n-1);
}
void update(ll pos, ll val) {
a[pos] = val;
update(1, 0, n-1, pos);
}
ll query(ll tl, ll tr) {
return query(1,0,n-1,tl,tr);
}
}
ll solve() {
ll best = 0;
ll best_id = -1;
ll last = n;
s.insert(0);
for (auto it = s.rbegin(); it != s.rend(); it ++) {
ll tmp = Y::query(*it, last-1);
if (Y::a[tmp] > best) {
best = Y::a[tmp];
best_id = tmp;
}
best *= X::a[*it];
const static ll INF = 1e9;
if (best > INF) {
break;
}
last = *it;
}
if (X::a[0] == 1) s.erase(0);
return Y::a[best_id] * X::query(best_id) % MOD;
}
ll init(ll N, ll X[], ll Y[]) {
n=N;
X::init(X);
Y::init(Y);
return solve();
}
ll updateX(ll pos, ll val) {
X::update(pos,val);
return solve();
}
ll updateY(ll pos, ll val) {
Y::update(pos, val);
return solve();
}
Compilation message
/usr/bin/ld: /tmp/ccXWEHdz.o: in function `main':
grader.c:(.text.startup+0xaa): undefined reference to `init(int, int*, int*)'
/usr/bin/ld: grader.c:(.text.startup+0x113): undefined reference to `updateX(int, int)'
/usr/bin/ld: grader.c:(.text.startup+0x16d): undefined reference to `updateY(int, int)'
collect2: error: ld returned 1 exit status