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;
using lint=__int128_t;
const lint mod=1e9+7;
const int lim=5e5+100;
const int inf=1e9;
int mul(lint i,lint j){
	return i*j%mod;
}
int n,*x,*y;
struct{
	int tree[4*lim];
	int P,VAL;
	int update(int l,int r,int node){
		if(l==r){
			return tree[node]=VAL;
		}
		int mid=(l+r)>>1,child=node<<1;
		if(P<=mid)return tree[node]=mul(update(l,mid,child),tree[child|1]);
		return tree[node]=mul(tree[child],update(mid+1,r,child|1));
	}
	void update(int p,int val){
		P=p,VAL=val;
		update(0,n-1,1);
	}
	int query(int l,int r,int node){
		if(r<=P){
			return tree[node];
		}
		int mid=(l+r)>>1,child=node<<1;
		if(P<=mid)return query(l,mid,child);
		return mul(tree[child],query(mid+1,r,child|1));
	}
	int query(int p){
		P=p;
		return query(0,n-1,1);
	}
}stmul;
struct{
	int tree[4*lim];
	int P,VAL;
	int update(int l,int r,int node){
		if(l==r)return tree[node]=VAL;
		int mid=(l+r)>>1,child=node<<1;
		if(P<=mid)return tree[node]=max(update(l,mid,child),tree[child|1]);
		return tree[node]=max(tree[child],update(mid+1,r,child|1));
	}
	void update(int p,int val){
		P=p,VAL=val;
		update(0,n-1,1);
	}
	int L,R;
	int query(int l,int r,int node){
		if(L<=l&&r<=R)return tree[node];
		if(r<L||R<l)return 0;
		int mid=(l+r)>>1,child=node<<1;
		return max(query(l,mid,child),query(mid+1,r,child|1));
	}
	int query(int l,int r){
		L=l,R=r;
		return query(0,n-1,1);
	}
}stmax;
set<int,greater<int>>nonones;
int findmax(){
	if(!nonones.size())return stmax.query(0,n-1);
	int past=*nonones.begin(),aa=stmax.query(past,n-1),bb=stmul.query(past);
	int curbest=mul(aa,bb),temp=mul(aa,x[past]);
	if(inf<temp)return curbest;
	for(auto p=next(nonones.begin());p!=nonones.end();p++){
		aa=stmax.query(*p,past-1);
		if(temp<aa){
			bb=stmul.query(*p);
			curbest=mul(aa,bb);
			temp=mul(aa,x[*p]);
		}else{
			temp=mul(temp,x[*p]);
		}
		if(inf<temp)return curbest;
		past=*p;
	}
	return curbest;
}
int init(int N, int X[], int Y[]) {
	n=N,x=X,y=Y;
	for(int i=0;i<n;i++){
		stmul.update(i,X[i]);
		stmax.update(i,Y[i]);
		if(X[i]!=1)nonones.insert(i);
	}
	return findmax();
}
int updateX(int pos, int val) {	
	if(x[pos]!=1)nonones.erase(pos);
	x[pos]=val;
	stmul.update(pos,val);
	if(x[pos]!=1)nonones.insert(pos);
	return findmax();
}
int updateY(int pos, int val) {
	stmax.update(pos,val);
	return findmax();
}
Compilation message (stderr)
horses.cpp: In function 'int mul(lint, lint)':
horses.cpp:13:12: warning: conversion from 'lint' {aka '__int128'} to 'int' may change value [-Wconversion]
   13 |  return i*j%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... |