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>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
const int MAXN = 500100;
const ll MOD = 1e9+7;
ll pwr (ll a, ll p) {
if (p == 0) return 1;
if (p == 1) return a%MOD;
ll ret = pwr(a, p/2);
ret = (ret*ret)%MOD;
if (p%2 == 1) ret = (ret*(a%MOD))%MOD;
return ret%MOD;
}
ll modInv (ll a) {
return pwr(a%MOD, MOD-2);
}
ll fen[MAXN];
void upd (int p, ll x) {
for (int i = p; i < MAXN; i += i&(-i))
fen[i] = (fen[i]*x)%MOD;
}
ll prefX (int p) {
ll ret = 1;
for (int i = p; i > 0; i -= i&(-i))
ret = (ret * fen[i])%MOD;
return ret;
}
int n;
ll x[MAXN], y[MAXN];
ll getMax () {
int id = 1;
if (n > 1000) id = max(1, n-40);
ll cr = 1;
FOR(i, id+1, n) {
cr *= x[i];
if (cr * y[i] > y[id]) {
id = i;
cr = 1;
}
}
ll ret = (prefX(id) * y[id])%MOD;
return ret;
}
int init(int N, int X[], int Y[]) {
n = N;
FOR(i, 1, n) x[i] = X[i-1];
FOR(i, 1, n) y[i] = Y[i-1];
FOR(i, 0, MAXN-1) fen[i] = 1;
FOR(i, 1, n) upd (i, x[i]);
return getMax();
}
int updateX(int pos, int val) {
pos++;
upd (pos, modInv(x[pos]));
x[pos] = val;
upd (pos, x[pos]);
return getMax();
}
int updateY(int pos, int val) {
pos++;
y[pos] = val;
return getMax();
}
Compilation message (stderr)
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:74:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
74 | return getMax();
| ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:82:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
82 | return getMax();
| ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:88:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
88 | return getMax();
| ~~~~~~^~
# | 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... |