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;
#define F first
#define S second
const ll mod=1e9+7;
ll a[500001], b[500001];
pair<pair<ll, ll>, pair<ll, ll>> st[2000001];
void build(ll xf, ll lf, ll rf){
if(lf==rf){
st[xf]={{a[lf], b[lf]}, {(a[lf]*b[lf]>=1e9), 1}};
return;
}
pair<pair<ll, ll>, pair<ll, ll>> c1, c2;
build(xf*2, lf, (lf+rf)/2);
build(xf*2+1, (lf+rf)/2+1, rf);
c1=st[xf*2];
c2=st[xf*2+1];
if(c2.S.F==1){
st[xf]={{(((st[xf*2].F.F*st[xf*2].S.S)%mod)*st[xf*2+1].F.F)%mod, st[xf*2+1].F.S}, {1, st[xf*2+1].S.S}};
}
else{
if(st[xf*2].F.S<st[xf*2].S.S*st[xf*2+1].F.F*st[xf*2+1].F.S){
st[xf]={{(((st[xf*2].F.F*st[xf*2].S.S)%mod)*st[xf*2+1].F.F)%mod, st[xf*2+1].F.S}, {(st[xf*2].S.F||(st[xf*2].S.S*st[xf*2+1].F.F*st[xf*2+1].F.S*st[xf*2].F.F)>=1e9), st[xf*2+1].S.S}};
}
else{
st[xf]=st[xf*2];
st[xf].S.S*=st[xf*2+1].S.S*st[xf*2+1].F.F;
}
}
return ;
}
ll n;
void update(ll xf, ll lf, ll rf, ll of){
if(rf<of||lf>of)return;
if(lf==rf){
st[xf]={{a[lf], b[lf]}, {(a[lf]*b[lf]>=1e9), 1}};
return;
}
pair<pair<ll, ll>, pair<ll, ll>> c1, c2;
build(xf*2, lf, (lf+rf)/2);
build(xf*2+1, (lf+rf)/2+1, rf);
c1=st[xf*2];
c2=st[xf*2+1];
if(c2.S.F==1){
st[xf]={{(((st[xf*2].F.F*st[xf*2].S.S)%mod)*st[xf*2+1].F.F)%mod, st[xf*2+1].F.S}, {1, st[xf*2+1].S.S}};
}
else{
if(st[xf*2].F.S<st[xf*2].S.S*st[xf*2+1].F.F*st[xf*2+1].F.S){
st[xf]={{(((st[xf*2].F.F*st[xf*2].S.S)%mod)*st[xf*2+1].F.F)%mod, st[xf*2+1].F.S}, {(st[xf*2].S.F||(st[xf*2].S.S*st[xf*2+1].F.F*st[xf*2+1].F.S*st[xf*2].F.F)>=1e9), st[xf*2+1].S.S}};
}
else{
st[xf]=st[xf*2];
st[xf].S.S*=st[xf*2+1].S.S*st[xf*2+1].F.F;
}
}
return ;
}
int init(int N, int X[], int Y[]) {
n=N;
for(int i=0; i<N; i++){
a[i+1]=X[i];
b[i+1]=Y[i];
}
build(1, 1, N);
return (st[1].F.F*st[1].F.S)%mod;
}
int updateX(int pos, int val) {
a[pos+1]=val;
update(1, 1, n, pos+1);
return (st[1].F.F*st[1].F.S)%mod;
}
int updateY(int pos, int val) {
b[pos+1]=val;
update(1, 1, n, pos+1);
return (st[1].F.F*st[1].F.S)%mod;
}
Compilation message (stderr)
horses.cpp: In function 'void build(ll, ll, ll)':
horses.cpp:12:40: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
12 | st[xf]={{a[lf], b[lf]}, {(a[lf]*b[lf]>=1e9), 1}};
| ~~~~~^~~~~~
horses.cpp:25:154: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
25 | st[xf]={{(((st[xf*2].F.F*st[xf*2].S.S)%mod)*st[xf*2+1].F.F)%mod, st[xf*2+1].F.S}, {(st[xf*2].S.F||(st[xf*2].S.S*st[xf*2+1].F.F*st[xf*2+1].F.S*st[xf*2].F.F)>=1e9), st[xf*2+1].S.S}};
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
horses.cpp: In function 'void update(ll, ll, ll, ll)':
horses.cpp:38:40: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
38 | st[xf]={{a[lf], b[lf]}, {(a[lf]*b[lf]>=1e9), 1}};
| ~~~~~^~~~~~
horses.cpp:51:154: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
51 | st[xf]={{(((st[xf*2].F.F*st[xf*2].S.S)%mod)*st[xf*2+1].F.F)%mod, st[xf*2+1].F.S}, {(st[xf*2].S.F||(st[xf*2].S.S*st[xf*2+1].F.F*st[xf*2+1].F.S*st[xf*2].F.F)>=1e9), st[xf*2+1].S.S}};
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:67:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
67 | return (st[1].F.F*st[1].F.S)%mod;
| ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:73:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
73 | return (st[1].F.F*st[1].F.S)%mod;
| ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:79:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
79 | return (st[1].F.F*st[1].F.S)%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... |