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 <bits/stdc++.h>
#include "horses.h"
#define maxN 500005
#define mod 1000000007
using namespace std;
struct segment{
long long a,b;
double la,lb;};
segment seg[4*maxN];
vector <long long> x,y;
void build(int n,int l,int d){
if(l==d){
seg[n].a=x[l];
seg[n].b=(x[l]*y[l])%mod;
seg[n].la=log2(x[l]);
seg[n].lb=log2(y[l])+seg[n].la;
}
else{
int m=(l+d)/2;
build(2*n,l,m);
build(2*n+1,m+1,d);
seg[n].a=(seg[2*n].a*seg[2*n+1].a)%mod;
seg[n].la=seg[2*n].la+seg[2*n+1].la;
if(seg[2*n].lb>seg[2*n+1].lb+seg[2*n].la){
seg[n].lb=seg[2*n].lb;
seg[n].b=seg[2*n].b;
}
else{
seg[n].lb=seg[2*n+1].lb+seg[2*n].la;
seg[n].b=(seg[2*n+1].b*seg[2*n].a)%mod;
}
}
}
void updatex(int n,int l,int d,int p,long long v){
if(l==d){
x[l]=v;
seg[n].a=x[l];
seg[n].b=(x[l]*y[l])%mod;
seg[n].la=log2(x[l]);
seg[n].lb=log2(y[l])+seg[n].la;
}
else{
int m=(l+d)/2;
if(p<=m) updatex(2*n,l,m,p,v);
else updatex(2*n+1,m+1,d,p,v);
seg[n].a=(seg[2*n].a*seg[2*n+1].a)%mod;
seg[n].la=seg[2*n].la+seg[2*n+1].la;
if(seg[2*n].lb>seg[2*n+1].lb+seg[2*n].la){
seg[n].lb=seg[2*n].lb;
seg[n].b=seg[2*n].b;
}
else{
seg[n].lb=seg[2*n+1].lb+seg[2*n].la;
seg[n].b=(seg[2*n+1].b*seg[2*n].a)%mod;
}
}
}
void updatey(int n,int l,int d,int p,long long v){
if(l==d){
y[l]=v;
seg[n].b=(x[l]*y[l])%mod;
seg[n].lb=log2(y[l])+seg[n].la;
}
else{
int m=(l+d)/2;
if(p<=m) updatey(2*n,l,m,p,v);
else updatey(2*n+1,m+1,d,p,v);
seg[n].a=(seg[2*n].a*seg[2*n+1].a)%mod;
seg[n].la=seg[2*n].la+seg[2*n+1].la;
if(seg[2*n].lb>seg[2*n+1].lb+seg[2*n].la){
seg[n].lb=seg[2*n].lb;
seg[n].b=seg[2*n].b;
}
else{
seg[n].lb=seg[2*n+1].lb+seg[2*n].la;
seg[n].b=(seg[2*n+1].b*seg[2*n].a)%mod;
}
}
}
int init(int n,int a[],int b[]){
int i;
long long ans;
for(i=0;i<n;i++){
x.push_back(a[i]%mod);
y.push_back(b[i]%mod);
}
build(1,0,n-1);
ans=seg[1].b%mod;
return (int) ans;
}
int updateX(int pos,int val){
long long ans;
updatex(1,0,x.size()-1,pos,(long long) val);
ans=seg[1].b%mod;
return (int) ans;
}
int updateY(int pos,int val){
long long ans;
updatey(1,0,y.size()-1,pos,(long long) val);
ans=seg[1].b%mod;
return (int) ans;
}
Compilation message (stderr)
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:97:43: warning: conversion to 'int' from 'std::vector<long long int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
updatex(1,0,x.size()-1,pos,(long long) val);
^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:103:43: warning: conversion to 'int' from 'std::vector<long long int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
updatey(1,0,y.size()-1,pos,(long long) val);
^
# | 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... |