# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
174661 | mat_v | Horses (IOI15_horses) | C++14 | 0 ms | 0 KiB |
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<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];
double lgx[maxn];
double lgy[maxn];
double niz[maxn];
ll pro[4 * maxn];
///
struct cvor{
double lg;
ll pref;
int poz;
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, double lgval, ll val){
propagate(node, l, r);
if(r < levo || desno < levo)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] = log(1.0 * x[i]);
lgy[i] = log(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) {
return res;
}
int updateY(int pos, int val) {
return res;
}