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 long double ld;
struct drvo{
ld val;
ld lazy;
ll prod;
ll lazyprod;
} seg[4000000];
ld x[1000005];
ld y[1000005];
ld xpref[1000005];
ll u1[1000005];
ll xprod[1000005];
ll x1[1000005];
ll n;
const int MOD = 1000000007;
ll mul(ll a, ll b){
return (1LL*a*b)%MOD;
}
ll pw(ll a, ll b){
if(b == 0) return 1;
ll res = pw(a, b/2);
res = (res*res)%MOD;
if(b%2) res = (res*a)%MOD;
return res;
}
/*
ll pww(ld x){
ll y = x;
x -= y;
ld res = pw(2, y);
ld jos = pow(2, x);
res *= jos;
return round(res);
}*/
void seginit(ll node, ll l, ll r){
seg[node].lazyprod = 1;
if(l == r){
seg[node].val = xpref[l] + y[l];
seg[node].prod = mul(xprod[l], u1[l]);
return;
}
ll mid = (l+r)/2;
seginit(node*2, l, mid);
seginit(node*2+1, mid+1, r);
if(seg[node*2].val > seg[node*2+1].val){
seg[node].val = seg[node*2].val;
seg[node].prod = seg[node*2].prod;
}
else{
seg[node].val = seg[node*2+1].val;
seg[node].prod = seg[node*2+1].prod;
}
}
void propagate(ll node, ll l, ll r){
seg[node].val += seg[node].lazy;
seg[node].prod = mul(seg[node].prod, seg[node].lazyprod);
if(l == r){
seg[node].lazy = 0;
seg[node].lazyprod = 1;
return;
}
seg[node*2].lazy += seg[node].lazy;
seg[node*2].lazyprod = mul(seg[node*2].lazyprod, seg[node].lazyprod);
seg[node*2+1].lazy += seg[node].lazy;
seg[node*2+1].lazyprod = mul(seg[node*2+1].lazyprod, seg[node].lazyprod);
seg[node].lazy = 0;
seg[node].lazyprod = 1;
}
void upd(ll node, ll l, ll r, ll tl, ll tr, ld val, ll prod){
propagate(node, l, r);
if(l > tr || tl > r) return;
if(tl <= l && r <= tr){
seg[node].lazy += val;
seg[node].lazyprod = mul(seg[node].lazyprod, prod);
propagate(node, l, r);
return;
}
ll mid = (l+r)/2;
upd(node*2, l, mid, tl, tr, val, prod);
upd(node*2+1, mid+1, r, tl, tr, val, prod);
if(seg[node*2].val > seg[node*2+1].val){
seg[node].val = seg[node*2].val;
seg[node].prod = seg[node*2].prod;
}
else{
seg[node].val = seg[node*2+1].val;
seg[node].prod = seg[node*2+1].prod;
}
}
int init(int N, int X[], int Y[]) {
n = N;
xprod[0] = 1;
for(ll i=0; i<N; i++){
x[i+1] = logl(X[i]);
x1[i+1] = X[i];
xpref[i+1] = x[i+1] + xpref[i];
xprod[i+1] = mul(xprod[i], X[i]);
y[i+1] = logl(Y[i]);
u1[i+1] = Y[i];
//cout << xpref[i] << " " << y[i+1] << endl;
}
seginit(1, 1, n);
//cout << seg[1].val << endl;
return seg[1].prod;
}
int updateX(int pos, int val){
pos++;
ld g = x[pos];
x[pos] = logl(val);
ll f = x1[pos];
x1[pos] = val;
upd(1, 1, n, pos, n, x[pos]-g, mul(x1[pos], pw(f, MOD-2)));
return seg[1].prod;
}
int updateY(int pos, int val) {
pos++;
ld g = y[pos];
y[pos] = logl(val);
ll f = u1[pos];
u1[pos] = val;
upd(1, 1, n, pos, pos, y[pos]-g, pw(f, MOD-2));
return seg[1].prod;
}
Compilation message (stderr)
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:121:19: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return seg[1].prod;
~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:131:16: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return seg[1].prod;
~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:141:16: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return seg[1].prod;
~~~~~~~^~~~
# | 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... |