# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
416663 | victoriad | Horses (IOI15_horses) | C++14 | 0 ms | 0 KiB |
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 <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <utility>
#include <stack>
#include <vector>
#include <fstream>
#include <map>
using namespace std;
int mod=1e9+7;
vector<long long int>lista1;
vector<int>lista2;
vector<int>lista3;
vector<double>lista4;
int m;
double lm;
int init(int N, int X[], int Y[]) {
lista1.resize(N);
lista2.resize(N);
lista3.resize(N);
lista4.resize(N);
for(int i=0;i<N;i++)lista2[i]=Y[i];
for(int i=0;i<N;i++)lista3[i]=X[i];
double j=0;
double r2=0;
int a=1;
int o=0;
for(int i=0;i<N;i++){
r2+=log10(X[i]);
lista4[i]=r2;
a%=mod;
lista1[i]=(a*X[i])%mod;
lista1[i]%=mod;
a=lista1[i];
if(r2+log10(Y[i])>j){
j=r2+log10(Y[i]);
o=i;
}
}
lm=j;
for(int i=0;i<N;i++)cout<<lista1[i];
m=((lista1[o]%mod)*Y[o])%mod;
return m;
}
int updateX(int pos, int val) {
double j=0;
double r2=0;
int a=1;
int o=0;
lista3[pos]=val;
for(int i=0;i<lista1.size();i++){
r2+=log10(lista3[i]);
lista4[i]=r2;
a%=mod;
lista1[i]=(a*lista3[i])%mod;
lista1[i]%=mod;
a=lista1[i];
if(r2+log10(lista2[i])>j){
j=r2+log10(lista2[i]);
o=i;
}
}
lm=j;
m=((lista1[o]%mod)*lista2[o])%mod;
return m;
}
int updateY(int pos, int val) {
if(lm<lista4[pos]+log10(val)){
m=(lista1[pos]*val)%mod;
}
return m;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,m,a,b,c;
cin>>n;
int x[n],y[n];
for(int i=0;i<n;i++)cin>>x[i];
for(int i=0;i<n;i++)cin>>y[i];
cout<<init(n,x,y)<<"\n";
cin>>m;
while(m--){
cin>>a>>b>>c;
if(a==2){
cout<<updateX(b,c)<<"\n";
}
else{
cout<<updateY(b,c)<<"\n";
}
}
return 0;
}