# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
310271 | juggernaut | 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>
#include"grader.cpp"
using namespace std;
typedef long long ll;
ll mod=1e9+7;
struct node{
ll ans,cur,need;
double lg;
}tree[2000000];
ll n,res=1,x[500005],y[500005];
double loga=0;
void build(ll v,ll l,ll r){
if(l==r){
res=(res*x[l])%mod;
loga+=log2(x[l]);
tree[v].ans=(res*y[l])%mod;
tree[v].lg=loga+log2(y[l]);
tree[v].cur=(x[l]*y[l])%mod;
tree[v].need=(x[l]*y[l])%mod;
return;
}
ll mid=(l+r)>>1;
build(v<<1,l,mid);
build((v<<1)+1,mid+1,r);
if(tree[v<<1].lg>tree[(v<<1)+1].lg)tree[v]=tree[v<<1];
else tree[v]=tree[(v<<1)+1];
}
ll pw(ll a,ll b){
if(!b)return 1ll;
if(b&1)return (a*pw(a,b-1))%mod;
ll x=pw(a,b>>1);
return (x*x)%mod;
}
void push(int v,int l,int r){
if(l!=r){
tree[v<<1].cur=tree[v<<1].need;
tree[v<<1].need=tree[v<<1].need;
tree[(v<<1)+1].cur=tree[(v<<1)+1].need;
tree[(v<<1)+1].need=tree[(v<<1)+1].need;
}
tree[v].lg-=log2(tree[v].cur);
tree[v].lg+=log2(tree[v].need);
tree[v].ans=(tree[v].ans*pw(tree[v].cur,mod-2))%mod;
tree[v].ans=(tree[v].ans*tree[v].need)%mod;
tree[v].cur=tree[v].need;
}
void update(ll v,ll l,ll r,ll ql,ll qr,ll val){
push(v,l,r);
if(qr<l||r<ql)return;
if(ql<=l&&r<=qr){
tree[v].cur=tree[v].need;
tree[v].need=val;
push(v,l,r);
return;
}
ll mid=(l+r)>>1;
update(v<<1,l,mid,ql,qr,val);
update((v<<1)+1,mid+1,r,ql,qr,val);
if(tree[v<<1].lg>tree[(v<<1)+1].lg)tree[v]=tree[v<<1];
else tree[v]=tree[(v<<1)+1];
}
int init(int N,int X[],int Y[]){
n=N;
copy(X,X+n,x);
copy(Y,Y+n,y);
build(1,0,n-1);
push(1,0,n-1);
return tree[1].ans;
}
int updateX(int pos,int val){
update(1,0,n-1,pos,n-1,(1ll*val*y[pos])%mod);
x[pos]=val;
push(1,0,n-1);
return tree[1].ans;
}
int updateY(int pos,int val){
update(1,0,n-1,pos,pos,(1ll*val*x[pos])%mod);
y[pos]=val;
push(1,0,n-1);
return tree[1].ans;
}