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 "horses.h"
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int n;
vector<ll> x, y, tr;
void build(int v, int l, int r){
if (l == r){
tr[v] = x[l];
return;
}
int mid = (l + r) / 2;
build(v * 2, l, mid);
build(v * 2 + 1, mid + 1, r);
tr[v] = (tr[v * 2] * tr[v * 2 + 1]) % mod;
}
void update(int v, int l, int r, int pos, ll val){
if (l == r){
tr[v] = val;
}
else{
int mid = (l + r) / 2;
if (pos <= mid){
update(v * 2, l, mid, pos, val);
}
else{
update(v * 2 + 1, mid + 1, r, pos, val);
}
tr[v] = (tr[v * 2] * tr[v * 2 + 1]) % mod;
}
}
ll query(int v, int l, int r, int ql, int qr){
if (l > qr || r < ql){
return 1;
}
else if (ql <= l && r <= qr){
return tr[v];
}
int mid = (l + r) / 2;
return (query(v * 2, l, mid, ql, qr) * query(v * 2 + 1, mid + 1, r, ql, qr)) % mod;
}
ll calc(){
ll ti = 1, in = n - 1;
for (int i = n - 1; i >= 0; i--){
ti *= x[i];
if (ti < mod){
in--;
}
else{
break;
}
}
ll ma = 0;
ll prmult = 1;
for (int i = 0; i < n; i++){
prmult *= x[i];
ma = max(ma, 1ll * prmult * y[i]);
}
ll ext = 1;
/*if (ti != 0){
ext = query(1, 0, n - 1, 0, ti - 1);
}*/
return ((ma % mod) * ext) % mod;
}
int init(int N, int X[], int Y[]) {
n = N;
x.resize(N), y.resize(N), tr.assign(N * 4, 1);
for (int i = 0; i < N; i++){
x[i] = X[i];
y[i] = Y[i];
}
build(1, 0, n - 1);
return calc();
}
int updateX(int pos, int val){
x[pos] = val;
update(1, 0, n - 1, pos, val);
return calc();
}
int updateY(int pos, int val){
y[pos] = val;
return calc();
}
Compilation message (stderr)
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:74:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
74 | return calc();
| ~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:80:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
80 | return calc();
| ~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:85:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
85 | return calc();
| ~~~~^~
# | 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... |