# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1016312 | ayankarimova | 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 "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
const ll mod=1e9+7;
const ll sz=5e+5;
struct d
{
double sum, lpre;
ll mul, pre;
};
d st[sz*4];
ll x[sz], y[sz], n;
double xl[sz], yl[sz];
d make(ll pos)
{
d cur;
cur.sum=xl[pos];
cur.mul=x[pos];
cur.lpre=xl[pos]+yl[pos];
cur.pre=(x[pos]*y[pos])%mod;
return cur;
}
void mrg(d a, d b, d &c)
{
c.sum=a.sum+b.sum;
c.mul=(a.mul*b.mul)%mod;
if(a.lpre>a.sum+b.lpre){
c.lpre=a.lpre;
c.pre=a.pre;
}
else{
c.lpre=a.sum+b.lpre;
c.pre=(a.mul*b.pre)%mod;
}
}
void build(ll l, ll r, ll in)
{
if(l==r){
st[in]=make(l);
return;
}
ll mid=(l+r)/2;
build(l, mid, in*2);
build(mid+1, r, in*2+1);
mrg(st[in*2], st[in*2+1], st[in]);
}
void update(ll l, ll r, ll in, ll pos)
{
if(l==r){
st[in]=make(l);
return;
}
ll mid=(l+r)/2;
if(pos<=mid){
update(l, mid, in*2, pos);
}
else{
update(mid+1, r, in*2+1, pos);
}
mrg(st[in*2], st[in*2+1], st[in]);
}
ll init(int N, int X[], int Y[]) {
ll num=1, ans=0;
n=N;
for(int i=0; i<n; i++){
x[i+1]=(X[i]);
y[i+1]=(Y[i]);
xl[i+1]=log10(X[i]);
yl[i+1]=log10(Y[i]);
}
build(1, n, 1);
return st[1].pre;
}
ll updateX(int pos, int val) {
pos++;
x[pos]=val;
xl[pos]=log10(val);
update(1, n, 1, pos);
return st[1].pre;
}
ll updateY(int pos, int val) {
pos++;
y[pos]=val;
yl[pos]=log10(val);
update(1, n, 1, pos);
return st[1].pre;
}