이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
#include "horses.h"
const ll MOD = 1e9 + 7;
const ll MAX = 1e9 + 5;
ll norm(ll x) {
x %= MOD;
x += MOD;
x %= MOD;
return x;
}
ll binpow(ll x, ll y) {
x = norm(x);
ll res = 1;
while (y > 0) {
if (y % 2 == 1)
res = norm(res * x);
x = norm(x * x);
y /= 2;
}
return res;
}
ll inv(ll x) {
return binpow(x, MOD - 2);
}
int N;
vi X;
vi Y;
ll prodall = 1; // product of all X_i
ll solve() {
int bestp = N - 1;
ll currn = Y[N - 1];
ll currd = 1;
ll bestn = currn;
ll bestd = currd;
for (int i = N - 2; i >= 0; i--) {
currn = Y[i];
currd *= X[i + 1];
if (currd >= MAX)
break;
if (currn * bestd > bestn * currd) {
bestp = i;
bestn = currn;
bestd = currd;
}
}
ll ans = prodall;
for (int i = bestp + 1; i < N; i++) {
ans *= inv(X[i]);
ans = norm(ans);
}
ans *= Y[bestp];
ans = norm(ans);
return ans;
}
int init(int n, int x[], int y[]) {
N = n;
X = vi(N); Y = vi(N);
for (int i = 0; i < N; i++) {
X[i] = x[i];
Y[i] = y[i];
}
for (int i = 0; i < N; i++) {
prodall *= X[i];
prodall = norm(prodall);
}
ll ans = solve();
return (int)(ans);
}
int updateX(int pos, int val) {
prodall = norm(prodall * inv(X[pos]));
X[pos] = val;
prodall = norm(prodall * X[pos]);
ll ans = solve();
return (int)(ans);
}
int updateY(int pos, int val) {
Y[pos] = val;
ll ans = solve();
return (int)(ans);
}
# | 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... |