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 <stdio.h>
#include <math.h>
#define MOD 1000000007LL
typedef struct node node;
struct node
{
long long X, Y, Ans;
double logX, logY, logAns;
};
node Seg[2000005];
long long x[500005], y[500005];
void calc(int cell)
{
if (Seg[2*cell + 2].logAns + Seg[2*cell + 2].logY + Seg[2*cell + 1].logX > Seg[2*cell + 1].logAns + Seg[2*cell + 1].logY)
{
Seg[cell].X = (Seg[2*cell + 1].X*Seg[2*cell + 2].X)%MOD;
Seg[cell].logX = Seg[2*cell + 1].logX + Seg[2*cell + 2].logX;
Seg[cell].Y = Seg[2*cell + 2].Y;
Seg[cell].logY = Seg[2*cell + 2].logY;
Seg[cell].Ans = (Seg[2*cell + 1].X*Seg[2*cell + 2].Ans)%MOD;
Seg[cell].logAns = Seg[2*cell + 1].logX + Seg[2*cell + 2].logAns;
}
else
{
Seg[cell].X = (Seg[2*cell + 1].X*Seg[2*cell + 2].X)%MOD;
Seg[cell].logX = Seg[2*cell + 1].logX + Seg[2*cell + 2].logX;
Seg[cell].Y = Seg[2*cell + 1].Y;
Seg[cell].logY = Seg[2*cell + 1].logY;
Seg[cell].Ans = Seg[2*cell + 1].Ans;
Seg[cell].logAns = Seg[2*cell + 1].logAns;
}
// printf("%llu %llu %llu\n", Seg[cell].X, Seg[cell].Y, Seg[cell].Ans);
}
void makeTree(int s, int e, int cell)
{
if (s == e)
{
Seg[cell].X = x[s];
Seg[cell].Y = y[s];
Seg[cell].logX = log(x[s]);
Seg[cell].logY = log(y[s]);
Seg[cell].Ans = x[s];
Seg[cell].logAns = Seg[cell].logX;
return;
}
int m = (s + e)/2;
makeTree(s, m, 2*cell + 1);
makeTree(m + 1, e, 2*cell + 2);
calc(cell);
}
int n;
int init(int N, int X[], int Y[])
{
int i;
n = N;
for (i = 0; i < N; i++)
x[i] = (long long) X[i];
for (i = 0; i < N; i++)
y[i] = (long long) Y[i];
makeTree(0, N - 1, 0);
long long r = (Seg[0].Y*Seg[0].Ans)%MOD;
return (int) r;
}
void updX(int pos, long long val, int s, int e, int cell)
{
if (s == e)
{
Seg[cell].X = val;
Seg[cell].logX = log(val);
Seg[cell].Ans = Seg[cell].X;
Seg[cell].logAns = Seg[cell].logX;
return;
}
int m = (s + e)/2;
if (pos <= m)
updX(pos, val, s, m, 2*cell + 1);
else
updX(pos, val, m + 1, e, 2*cell + 2);
calc(cell);
}
int updateX(int pos, int val)
{
updX(pos, (long long) val, 0, n - 1, 0);
long long r = (Seg[0].Y*Seg[0].Ans)%MOD;
return (int) r;
}
void updY(int pos, long long val, int s, int e, int cell)
{
if (s == e)
{
Seg[cell].Y = val;
Seg[cell].logY = log(val);
return;
}
int m = (s + e)/2;
if (pos <= m)
updY(pos, val, s, m, 2*cell + 1);
else
updY(pos, val, m + 1, e, 2*cell + 2);
calc(cell);
}
int updateY(int pos, int val)
{
updY(pos, (long long) val, 0, n - 1, 0);
long long r = (Seg[0].Y*Seg[0].Ans)%MOD;
return (int) r;
}
Compilation message (stderr)
horses.cpp: In function 'void makeTree(int, int, int)':
horses.cpp:41:28: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
Seg[cell].logX = log(x[s]);
^
horses.cpp:42:28: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
Seg[cell].logY = log(y[s]);
^
horses.cpp: In function 'void updX(int, long long int, int, int, int)':
horses.cpp:70:27: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
Seg[cell].logX = log(val);
^
horses.cpp: In function 'void updY(int, long long int, int, int, int)':
horses.cpp:93:27: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
Seg[cell].logY = log(val);
^
# | 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... |