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"
#define REP(i,n) for(int i = 1; i <= (n); i++)
using namespace std;
#ifdef LOCAL
ifstream in("in.in");
ofstream out("out.out");
#endif
const int nmax = 1005;
long long n,x[nmax],y[nmax],inf = (1LL << 60),MOD = 1000000007;
double logx[nmax],logy[nmax];
int compute() {
double horses_log = 0,max_sol_log = -inf;
long long horses_mod = 1, max_sol_mod = -inf;
for (int i = 0; i < n; i++) {
horses_log = horses_log + logx[i];
horses_mod = horses_mod * x[i] % MOD;
if (horses_log + logy[i] > max_sol_log) {
max_sol_log = horses_log + logy[i];
max_sol_mod = horses_mod * y[i] % MOD;
}
}
return max_sol_mod % MOD;
}
int init(int tn, int* tx,int* ty) {
n = tn;
for (int i = 0; i < n; i++) {
x[i] = tx[i];
logx[i] = log(x[i]);
y[i] = ty[i];
logy[i] = log(ty[i]);
}
return compute();
}
int updateX(int pos, int val) {
x[pos] = val;
logx[pos] = log(x[pos]);
return compute();
}
int updateY(int pos, int val) {
y[pos] = val;
logy[pos] = log(y[pos]);
return compute();
}
#ifdef LOCAL
int tx[nmax],ty[nmax];
int32_t main() {
in >> n;
for (int i = 0; i < n; i++) {
in >> tx[i];
}
for (int i = 0; i < n; i++) {
in >> ty[i];
}
out << init(n,tx,ty) << "\n";
int m;
in >> m;
for (int i = 0; i < m; i++) {
int type,pos,val;
in >> type >> pos >> val;
if (type == 0) {
out << updateX(pos, val);
}
if (type == 1) {
out << updateY(pos,val);
}
}
}
#endif
Compilation message (stderr)
horses.cpp: In function 'int compute()':
horses.cpp:17:41: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
17 | double horses_log = 0,max_sol_log = -inf;
| ^~~~
horses.cpp:30:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
30 | return max_sol_mod % MOD;
| ~~~~~~~~~~~~^~~~~
# | 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... |