# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
68995 | theknife2001 | Horses (IOI15_horses) | C++17 | 207 ms | 21640 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 "grader.cpp"
#include <bits/stdc++.h>
#define mid (l+r)/2
using namespace std;
const int N=5e5+55;
long long tree[N*4];
long long x[N];
long long y[N];
int n;
int m=1e9+7;
void build(int l , int r , int node)
{
if(l==r)
{
tree[node]=x[l];
return ;
}
build(l,mid,node*2);
build(mid+1,r,node*2+1);
tree[node]=tree[node*2]*tree[node*2+1];
tree[node]%=m;
}
void update(int l , int r , int node , int ind , int val)
{
if(l==r&&l==ind)
{
tree[node]=val;
return ;
}
if(ind<=mid)
update(l,mid,node*2,ind,val);
else
update(mid+1,r,node*2+1,ind,val);
tree[node]=tree[node*2]*tree[node*2+1];
tree[node]%=m;
}
long long query(int l , int r , int node , int x , int y)
{
if(x<=l&&r<=y)
return tree[node];
if(l>y||r<x)
return 1;
return (query(l,mid,node*2,x,y)*query(mid+1,r,node*2+1,x,y))%m;
}
int solve()
{
int i=n-1;
long long ret=0;
long long temp=1;
long long s=1;
while(i>=0)
{
s*=x[i];
i--;
if(s>10000000000)
break;
}
i++;
int bestpos=n-1;
for(;i<n;i++)
{
temp*=x[i];
if(y[i]*temp>ret)
{
ret=y[i]*temp;
bestpos=i;
}
}
return (y[bestpos]*query(0,n-1,1,0,bestpos))%m;
}
int init(int N, int X[], int Y[])
{
n=N;
for(int i=0;i<N;i++)
{
x[i]=X[i];
y[i]=Y[i];
}
build(0,n-1,1);
return solve();
}
int updateX(int pos, int val) {
x[pos]=val;
update(0,n-1,1,pos,val);
return solve();
}
int updateY(int pos, int val)
{
y[pos]=val;
return solve();
}
Compilation message (stderr)
# | 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... |