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>
#define pb push_back
using namespace std;
#include "horses.h"
const long long mod = 1e9 + 7;
vector<array<__int128, 2> > arr;
int n;
int init(int N, int X[], int Y[]) {
arr.resize(N);
n = N;
for(int i = 0; i < N; i++){
arr[i] = {X[i], Y[i]};
}
__int128 vl = 1;
int ind = 0;
for(int i = N-1; i >= 0; i--){
vl *= arr[i][0];
if(vl > mod){
ind = i;
break;
}
}
vl = 1;
__int128 precarp = 1;
for(int i = 0; i < ind; i++){
precarp = (precarp * arr[i][0])%mod;
}
__int128 ans = 0;
for(int i = ind; i < N; i++){
vl *= arr[i][0];
ans = max(ans, vl * arr[i][1]);
}
ans %= mod;
ans *= precarp;
ans %= mod;
int res = ans;
return res;
}
int updateX(int pos, int val) {
int N = n;
arr[pos][0] = val;
__int128 vl = 1;
int ind = 0;
for(int i = N-1; i >= 0; i--){
vl *= arr[i][0];
if(vl > mod){
ind = i;
break;
}
}
vl = 1;
__int128 precarp = 1;
for(int i = 0; i < ind; i++){
precarp = (precarp * arr[i][0])%mod;
}
__int128 ans = 0;
for(int i = ind; i < N; i++){
vl *= arr[i][0];
ans = max(ans, vl * arr[i][1]);
}
ans %= mod;
ans *= precarp;
ans %= mod;
int res = ans;
return res;
}
int updateY(int pos, int val){
int N = n;
arr[pos][1] = val;
__int128 vl = 1;
int ind = 0;
for(int i = N-1; i >= 0; i--){
vl *= arr[i][0];
if(vl > mod){
ind = i;
break;
}
}
vl = 1;
__int128 precarp = 1;
for(int i = 0; i < ind; i++){
precarp = (precarp * arr[i][0])%mod;
}
__int128 ans = 0;
for(int i = ind; i < N; i++){
vl *= arr[i][0];
ans = max(ans, vl * arr[i][1]);
}
ans %= mod;
ans *= precarp;
ans %= mod;
int res = ans;
return res;
}
/*
int main() {
int N;
cin>>N;
int *X = (int*)malloc(sizeof(int)*(unsigned int)N);
int *Y = (int*)malloc(sizeof(int)*(unsigned int)N);
for (int i = 0; i < N; i++) {
cin>>X[i];
}
for (int i = 0; i < N; i++) {
cin>>Y[i];
}
printf("%d\n",init(N,X,Y));
int M;
cin>>M;
for (int i = 0; i < M; i++) {
int type; cin>>type;
int pos; cin>>pos;
int val; cin>>val;
if (type == 1) {
printf("%d\n",updateX(pos,val));
} else if (type == 2) {
printf("%d\n",updateY(pos,val));
}
}
return 0;
}
*/
Compilation message (stderr)
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:41:15: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
41 | int res = ans;
| ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:71:15: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
71 | int res = ans;
| ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:101:15: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
101 | int res = 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... |