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;
typedef pair <ll, ll> pii;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) (int)(v).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9+7;
const int mxn = 5e5+7;
ll x[mxn], y[mxn];
int n;
struct Node{
int x, y;
double _x, _y;
};
int mult(int a, int b){
return ll(a*b)%mod;
}
Node combine(Node a, Node b){
Node res;
if(a._y > a._x+b._y){
res.y = a.y;
res._y = a._y;
}
else{
res.y = mult(a.x, b.y);
res._y = a._x+b._y;
}
res.x = mult(a.x, b.x);
res._x = a._x+b._x;
return res;
}
struct Tree{
Node tree[mxn*2];
void build(int v, int l, int r){
if(l == r){
tree[v].x = x[l];
tree[v].y = mult(y[l], x[l]);
tree[v]._x = log2(double(x[l]));
tree[v]._y = log2(double(y[l]))+log2(double(x[l]));
return;
}
int mid = (l+r) >> 1;
build(v>>1, l, mid);
build((v>>1)+1, mid+1, r);
tree[v] = combine(tree[v>>1], tree[(v>>1)+1]);
}
void update(int v, int l, int r, int pos){
if(pos == l && r == l){
tree[v].x = x[l];
tree[v].y = mult(y[l], x[l]);
tree[v]._x = log2(double(x[l]));
tree[v]._y = log2(double(y[l]))+log2(double(x[l]));
return;
}
int mid = (l+r) >> 1;
if(pos <= mid){
update(v>>1, l, mid, pos);
}
else{
update((v>>1)+1, mid+1, r, pos);
}
tree[v] = combine(tree[v>>1], tree[(v>>1)+1]);
}
int query(){
return tree[1].y;
}
} tree;
int init(int N, int X[], int Y[]) {
n = N;
copy(X, X+n, x);
copy(Y, Y+n, y);
tree.build(1, 0, n-1);
return tree.query();
}
int updateX(int pos, int val){
x[pos] = val;
tree.update(1, 0, n-1, pos);
return tree.query();
}
int updateY(int pos, int val){
y[pos] = val;
tree.update(1, 0, n-1, pos);
return tree.query();
}
/*
3
2 1 3
3 4 1
1
2 1 2
8
6
*/
Compilation message (stderr)
horses.cpp: In function 'int mult(int, int)':
horses.cpp:33:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
33 | return ll(a*b)%mod;
| ~~~~~~~^~~~
horses.cpp: In member function 'void Tree::build(int, int, int)':
horses.cpp:58:28: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
58 | tree[v].x = x[l];
| ~~~^
horses.cpp:59:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
59 | tree[v].y = mult(y[l], x[l]);
| ~~~^
horses.cpp:59:39: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
59 | tree[v].y = mult(y[l], x[l]);
| ~~~^
horses.cpp: In member function 'void Tree::update(int, int, int, int)':
horses.cpp:72:28: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
72 | tree[v].x = x[l];
| ~~~^
horses.cpp:73:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
73 | tree[v].y = mult(y[l], x[l]);
| ~~~^
horses.cpp:73:39: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
73 | tree[v].y = mult(y[l], x[l]);
| ~~~^| # | 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... |