This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
#define ll long long
const ll mod = 1000000007;
const ll mx = 1000000018;
ll n;
ll x[501010], y[501010];
ll t[2010101];
ll Mxt[2010101];
void build(int v, int vl, int vr) {
if (vl == vr) {
t[v] = x[vl] % mod;
Mxt[v] = vl;
return;
}
int vm = (vl + vr) / 2;
build(2 * v, vl, vm);
build(2 * v + 1, vm + 1, vr);
t[v] = (t[2 * v] * t[2 * v + 1]) % mod;
if (y[Mxt[2 * v]] > y[Mxt[2 * v + 1]])
Mxt[v] = Mxt[2 * v];
else
Mxt[v] = Mxt[2 * v + 1];
}
void upd(int v, int vl, int vr, int pos, ll val) {
if (vl == vr) {
t[v] = val % mod;
return;
}
int vm = (vl + vr) / 2;
if (pos <= vm)upd(2 * v, vl, vm, pos, val);
else upd(2 * v + 1, vm + 1, vr, pos, val);
t[v] = (t[2 * v] * t[2 * v + 1]) % mod;
}
void Mxupd(int v, int vl, int vr, int pos) {
if (vl == vr) {
Mxt[v] = vl;
return;
}
int vm = (vl + vr) / 2;
if (pos <= vm)Mxupd(2 * v, vl, vm, pos);
else Mxupd(2 * v + 1, vm + 1, vr, pos);
if (y[Mxt[2 * v]] > y[Mxt[2 * v + 1]])
Mxt[v] = Mxt[2 * v];
else
Mxt[v] = Mxt[2 * v + 1];
}
ll gt(int v, int vl, int vr, int l, int r) {
if (l <= vl && vr <= r)return t[v] % mod;
if (r < vl || vr < l)return 1ll;
int vm = (vl + vr) / 2;
return (gt(2 * v, vl, vm, l, r) * gt(2 * v + 1, vm + 1, vr, l, r)) % mod;
}
ll Mxgt(int v, int vl, int vr, int l, int r) {
if (l <= vl && vr <= r)return Mxt[v];
if (r < vl || vr < l)return -1;
int vm = (vl + vr) / 2;
ll f = Mxgt(2 * v, vl, vm, l, r);
ll s = Mxgt(2 * v + 1, vm + 1, vr, l, r);
if (f == -1)return s;
if (s == -1)return f;
if (y[f] < y[s])return s;
return f;
}
int opp() {
ll cnt = y[n - 1];
ll last = n - 1;
for (int i = n - 1; i > 0;) {
if (x[i] > mx / cnt)cnt = mx;
else cnt *= x[i];
if (cnt < y[i - 1]){last = i - 1;cnt = y[i - 1];continue;}
if (cnt == mx)break;
int l = -1, r = i - 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
int N = gt(1, 0, n - 1, mid, r);
if (N >= 2)l = mid;
else r = mid;
}
int p = Mxgt(1, 0, n - 1, r, i);
i = r;
if (cnt < y[p]){last = p;cnt = y[p];}
}
ll d = gt(1, 0, n - 1, 0, last);
return ((d % mod) * (y[last] % mod)) % mod;
}
int init(int N, int X[], int Y[]) {
n = N;
for (ll i = 0; i < n; i++) {
x[i] = X[i];
y[i] = Y[i];
}
build(1, 0, n - 1);
return opp();
}
int updateX(int pos, int val) {
x[pos] = val;
upd(1, 0, n - 1, pos, val);
if (val == 0)exit(1);
return opp();
}
int updateY(int pos, int val) {
y[pos] = val;
Mxupd(1, 0, n - 1, pos);
return opp();
}
Compilation message (stderr)
horses.cpp: In function 'int opp()':
horses.cpp:72:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
72 | for (int i = n - 1; i > 0;) {
| ~~^~~
horses.cpp:82:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
82 | int N = gt(1, 0, n - 1, mid, r);
| ~~^~~
horses.cpp:82:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
82 | int N = gt(1, 0, n - 1, mid, r);
| ~~^~~~~~~~~~~~~~~~~~~~~
horses.cpp:86:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
86 | int p = Mxgt(1, 0, n - 1, r, i);
| ~~^~~
horses.cpp:86:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
86 | int p = Mxgt(1, 0, n - 1, r, i);
| ~~~~^~~~~~~~~~~~~~~~~~~
horses.cpp:90:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
90 | ll d = gt(1, 0, n - 1, 0, last);
| ~~^~~
horses.cpp:90:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
90 | ll d = gt(1, 0, n - 1, 0, last);
| ^~~~
horses.cpp:91:42: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
91 | return ((d % mod) * (y[last] % mod)) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:99:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
99 | build(1, 0, n - 1);
| ~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:105:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
105 | upd(1, 0, n - 1, pos, val);
| ~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:112:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
112 | Mxupd(1, 0, n - 1, pos);
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |