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 mod 1000000007
#define maxn 500005
#define xx first
#define yy second
using namespace std;
typedef long long ll;
typedef pair<long double,ll>pdl;
ll add(ll x, ll y){
return (x + y)%mod;
}
bool preso = 0;
ll mul(ll x, ll y){
if(x * y >= mod)preso = 1;
return (x * y)%mod;
}
ll power(ll x, ll y){
if(y == 0)return 1;
ll pola = power(x, y / 2);
pola = mul(pola, pola);
if(y%2 == 1)pola = mul(pola, x);
return pola;
}
ll inverz(ll x){
return power(x, mod - 2);
}
int n;
ll x[maxn];
ll y[maxn];
long double lgx[maxn];
long double lgy[maxn];
long double niz[maxn];
ll pro[4 * maxn];
///
struct cvor{
long double lg;
ll pref;
int poz;
long double lazylg;
ll lazy;
}seg[4 * maxn];
void seginit(int node, int l, int r){
seg[node].lazy = 1;
if(l == r){
seg[node].lg = niz[l];
seg[node].poz = l;
seg[node].pref = pro[l];
return;
}
int mid = (l + r) / 2;
seginit(node * 2, l, mid);
seginit(node * 2 + 1, mid + 1, r);
if(seg[node * 2].lg > seg[node * 2 + 1].lg)seg[node].pref = seg[node * 2].pref;
else seg[node].pref = seg[node * 2 + 1].pref;
seg[node].lg = max(seg[node * 2].lg, seg[node * 2 + 1].lg);
}
void propagate(int node, int l, int r){
seg[node].lg += seg[node].lazylg;
seg[node].pref = mul(seg[node].pref, seg[node].lazy);
if(l != r){
seg[node * 2].lazylg += seg[node].lazylg;
seg[node * 2 + 1].lazylg += seg[node].lazylg;
seg[node * 2].lazy = mul(seg[node * 2].lazy, seg[node].lazy);
seg[node * 2 + 1].lazy = mul(seg[node * 2 + 1].lazy, seg[node].lazy);
}
seg[node].lazylg = 0;
seg[node].lazy = 1;
}
void update(int node, int l, int r, int levo, int desno, long double lgval, ll val){
propagate(node, l, r);
if(r < levo || desno < l)return;
if(r <= desno && l >= levo){
seg[node].lazylg += lgval;
seg[node].lazy = mul(seg[node].lazy, val);
propagate(node, l, r);
return;
}
int mid = (l + r) / 2;
update(node * 2, l, mid, levo, desno, lgval, val);
update(node * 2 + 1, mid + 1, r, levo, desno, lgval, val);
if(seg[node * 2].lg > seg[node * 2 + 1].lg)seg[node].pref = seg[node * 2].pref;
else seg[node].pref = seg[node * 2 + 1].pref;
seg[node].lg = max(seg[node * 2].lg, seg[node * 2 + 1].lg);
}
pdl query(int node, int l, int r, int levo, int desno){
propagate(node, l, r);
if(desno < l || levo > r)return {0, 0};
if(l >= levo && r <= desno){
return {seg[node].lg, seg[node].pref};
}
int mid = (l + r) / 2;
pdl levi = query(node * 2, l, mid, levo, desno);
pdl desni = query(node * 2 + 1, mid + 1, r, levo, desno);
return max(levi, desni);
}
int init(int N, int X[], int Y[]) {
n = N;
y[0] = 1;
for(int i=1; i<=n; i++){
x[i] = X[i - 1];
y[i] = Y[i - 1];
lgx[i] = log10(1.0 * x[i]);
lgy[i] = log10(1.0 * y[i]);
}
ll p = 1;
for(int i=1; i<=n; i++){
niz[i] = niz[i - 1] - lgy[i - 1] + lgx[i] + lgy[i];
p = mul(p, x[i]);
pro[i] = mul(p, y[i]);
}
seginit(1,1,n);
return query(1,1,n,1,n).yy;
}
int updateX(int pos, int val){
pos++;
update(1,1,n,pos,n,log10(1.0 * val) - lgx[pos], mul(val, inverz(x[pos])));
lgx[pos] = log10(val);
x[pos] = val;
return query(1,1,n,1,n).yy;
}
int updateY(int pos, int val) {
pos++;
update(1,1,n,pos,pos,log10(1.0 * val) - lgy[pos], mul(val, inverz(y[pos])));
lgy[pos] = log10(val);
y[pos] = val;
return query(1,1,n,1,n).yy;
}
Compilation message (stderr)
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:110:33: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
lgx[i] = log10(1.0 * x[i]);
~~~^
horses.cpp:111:33: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
lgy[i] = log10(1.0 * y[i]);
~~~^
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
#define yy second
^
horses.cpp:120:29: note: in expansion of macro 'yy'
return query(1,1,n,1,n).yy;
^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
#define yy second
^
horses.cpp:128:26: note: in expansion of macro 'yy'
return query(1,1,n,1,n).yy;
^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
#define yy second
^
horses.cpp:136:26: note: in expansion of macro 'yy'
return query(1,1,n,1,n).yy;
^~
# | 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... |