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>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ll long long
const int NMAX = (int)1e5 * 6;
const ll MOD = (int)1e9 + 7;
int A[NMAX],B[NMAX],n;
ll over_two[NMAX],prod[NMAX];
ll POW(ll x,int p) {
ll res = 1;
while (p) {
if (p % 2)
res = res * x % MOD;
p /= 2;
x = x * x % MOD;
}
return res;
}
int init(int N, int X[], int Y[]) {
prod[0] = 1;
for (int i = 0; i < N;++i) {
A[i] = X[i];
B[i] = Y[i];
int g = 0;
int aux = X[i];
while (aux) {
aux /= 2;
++g;
}
over_two[i] = g - 1;
prod[i] = X[i];
if (i) {
over_two[i] += over_two[i - 1];
prod[i] = prod[i] * prod[i - 1] % MOD;
}
}
n = N;
ll ans = (ll)X[0] * (ll)Y[0] % MOD;
ll y_ans = Y[0];
int i_ans = 0;
ll x = X[0];
for (int i = 1; i < N;++i) {
x = x * (ll)X[i] % MOD;
bool ok = false;
if (over_two[i] - over_two[i_ans] > 33)
ok = true;
if (Y[i] * (prod[i] * POW(prod[i_ans],MOD - 2) % MOD) > y_ans)
ok = true;
if (ok) {
y_ans = Y[i];
i_ans = i;
ans = x * Y[i] % MOD;
}
}
return ans;
}
int updateX(int pos, int val) {
A[pos] = val;
return init(n,A,B);
}
int updateY(int pos, int val) {
B[pos] = val;
return init(n,A,B);
}
Compilation message (stderr)
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:58:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
58 | return 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... |