# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96429 | figter001 | 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;
typedef long long ll;
typedef long double ld;
const int maxn = 5e5 + 50;
const int mod = 1e9+7;
pair<ld,int> lgs[(1<<20)];
ld sum[maxn],lazy1[(1<<20)],val1;
ll seg[(1<<20)],y[maxn],x[maxn],val2;
int n,l,r;
ll Pow(ll a,ll b){
if(!b)return 1;
ll ret = Pow(a,b/2);
if(b%2)return ((ret*ret)%mod*a)%mod;
return (ret&ret)%mod;
}
void build1(int n,int s,int e){
if(s == e){
lgs[n] = {sum[s] + log((ld)y[s]),s};
return;
}
build1(n*2,s,(s+e)/2);
build1(n*2+1,(s+e)/2+1,e);
lgs[n] = max(lgs[n*2],lgs[n*2+1]);
}
void build2(int n,int s,int e){
if(s == e){
seg[n] = x[s];
return;
}
build2(n*2,s,(s+e)/2);
build2(n*2+1,(s+e)/2+1,e);
seg[n] = (seg[n*2] * seg[n*2+1])%mod;
}
void update1(int n,int s,int e){
if(s > r || e < l)return;
if(s >= l && e <= r){
lazy1[n] += val1;
pro1(n,s,e);
return;
}
update1(n*2,s,(s+e)/2);
update1(n*2+1,(s+e)/2+1,e);
lgs[n] = max(lgs[n*2],lgs[n*2+1]);
}
void update2(int n,int s,int e){
if(s > r || e < l)return;
if(s >= l && e <= r){
seg[n] = val;
return;
}
update2(n*2,s,(s+e)/2);
update2(n*2+1,(s+e)/2+1,e);
seg[n] = (seg[n*2] * seg[n*2+1])%mod;
}
int get(int n,int s,int e){
pro2(n,s,e);
if(s > r || e < l)return 1;
if(s >= l && e <= r)return (int)seg[n];
return get(n*2,s,(s+e)/2) * get(n*2+1,(s+e)/2+1,e);
}
int solve(){
l = 1;
r = lgs[1].second;
return (get(1,1,n) * y[r])%mod;
}
int init(int N, int X[], int Y[]){
n = N;
for(int i=1;i<=n;i++){
y[i] = Y[i-1];
x[i] = X[i-1];
sum[i] = sum[i-1] + log((ld)x[i]);
}
build1(1,1,n);
build2(1,1,n);
return solve();
}
int updateX(int pos, int val) {
pos++;
val1 = log((ld)val) - log((ld)x[pos]);
val2 = val;
x[pos] = val;
l = pos;
r = n;h
update1(1,1,n);
l = r = pos;
update2(1,1,n);
return solve();
}
int updateY(int pos, int val) {
pos++;
val1 = log((ld)val) - log((ld)y[pos]);
y[pos] = val;
l = r = pos;
update1(1,1,n);
return solve();
}