#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
#define foru(i,a,b) for(int i=(a); i<=(b); ++i)
#define ford(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define bit(s,i) (((s)>>(i))&1)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fi first
#define se second
#define ll long long
#define eb emplace_back
#define pb push_back
#define __builtin_popcount __builtin_popcountll
#define _ << " " <<
template <class X, class Y> bool maxi(X &x, Y y){return x<y?x=y,true:false;}
template <class X, class Y> bool mini(X &x, Y y){return x>y?x=y,true:false;}
const int mod=1e9+7;
const int N=505050;
const int INF=2e9;
int n,X[N],Y[N];
#define lc id<<1
#define rc id<<1|1
struct{
int st[N<<2], st2[N<<2];
void build(int id=1, int l=0, int r=n-1){
if(l==r){
st[id]=st2[id]=X[l];
return;
}
int mid=(l+r)>>1;
build(lc,l,mid);
build(rc,mid+1,r);
st[id]=min((ll)INF, 1LL*st[lc]*st[rc]);
st2[id]=1LL*st2[lc]*st2[rc] % mod;
}
void upd(int x, int val){
int id=1, l=0, r=n-1;
while(l<r){
int mid=(l+r)>>1;
if(x<=mid) id=lc, r=mid;
else id=rc, l=mid+1;
}
st[id]=st2[id]=val;
while(id>1){
id/=2;
st[id]=min((ll)INF, 1LL*st[lc]*st[rc]);
st2[id]=1LL*st2[lc]*st2[rc] % mod;
}
}
int get(int u, int v, int id=1, int l=0, int r=n-1){
if(u<=l&&r<=v) return st[id];
int mid=(l+r)>>1;
if(v<=mid) return get(u,v,lc,l,mid);
if(u>mid) return get(u,v,rc,mid+1,r);
return min((ll)INF, 1LL*get(u,v,lc,l,mid)*get(u,v,rc,mid+1,r));
}
int getMod(int u, int v, int id=1, int l=0, int r=n-1){
if(u<=l&&r<=v) return st2[id];
int mid=(l+r)>>1;
if(v<=mid) return getMod(u,v,lc,l,mid);
if(u>mid) return getMod(u,v,rc,mid+1,r);
return 1LL*getMod(u,v,lc,l,mid)*getMod(u,v,rc,mid+1,r) % mod;
}
} s1;
struct{
int st[N<<2];
int comp(int x, int y){
if(s1.get(x+1,y) > Y[x]/Y[y]) return y;
return x;
}
void build(int id=1, int l=0, int r=n-1){
if(l==r){
st[id]=l;
return;
}
int mid=(l+r)>>1;
build(lc,l,mid);
build(rc,mid+1,r);
st[id]=comp(st[lc],st[rc]);
}
void upd(int x){
int id=1, l=0, r=n-1;
while(l<r){
int mid=(l+r)>>1;
if(x<=mid) id=lc, r=mid;
else id=rc, l=mid+1;
}
while(id>1){
id/=2;
st[id]=comp(st[lc],st[rc]);
}
}
} s2;
int init(int nn, int xx[], int yy[]) {
n=nn;
rep(i,n) X[i]=xx[i];
rep(i,n) Y[i]=yy[i];
s1.build();
s2.build();
int p=s2.st[1];
return 1LL*Y[p]*s1.getMod(0,p) % mod;
}
int updateX(int pos, int val) {
s1.upd(pos,val);
s2.upd(pos);
int p=s2.st[1];
return 1LL*Y[p]*s1.getMod(0,p) % mod;
}
int updateY(int pos, int val) {
Y[pos]=val;
s2.upd(pos);
int p=s2.st[1];
return 1LL*Y[p]*s1.getMod(0,p) % mod;
}
| # | 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... |