Submission #46213

#TimeUsernameProblemLanguageResultExecution timeMemory
46213RayaBurong25_1Horses (IOI15_horses)C++17
100 / 100
227 ms267400 KiB
#include "horses.h"
#include <math.h>
#include <algorithm>
#define MOD 1000000007LL
typedef struct node node;
struct node
{
	long long X, A;
	double lgX, lgA;
};
node Seg[2000005];
int n;
long long x[500005], y[500005];
void makeTree(int s, int e, int cell)
{
	if (s == e)
	{
		Seg[cell].X = x[s];
		Seg[cell].A = (x[s]*y[s])%MOD;
		Seg[cell].lgX = log(x[s]);
		Seg[cell].lgA = Seg[cell].lgX + log(y[s]);
		return;
	}
	int m = (s + e)/2;
	makeTree(s, m, 2*cell + 1);
	makeTree(m + 1, e, 2*cell + 2);
	Seg[cell].X = (Seg[2*cell + 1].X*Seg[2*cell + 2].X)%MOD;
	Seg[cell].lgX = Seg[2*cell + 1].lgX + Seg[2*cell + 2].lgX;
	if (Seg[2*cell + 1].lgA > Seg[2*cell + 1].lgX + Seg[2*cell + 2].lgA)
	{
		Seg[cell].lgA = Seg[2*cell + 1].lgA;
		Seg[cell].A = Seg[2*cell + 1].A;
	}
	else
	{
		Seg[cell].lgA = Seg[2*cell + 1].lgX + Seg[2*cell + 2].lgA;
		Seg[cell].A = (Seg[2*cell + 1].X*Seg[2*cell + 2].A)%MOD;
	}
}
int init(int N, int X[], int Y[])
{
	n = N;
	int i;
	for (i = 0; i < n; i++)
		x[i] = X[i];
	for (i = 0; i < n; i++)
		y[i] = Y[i];
	makeTree(0, n - 1, 0);
	return (int) Seg[0].A;
}
void update(int pos, int s, int e, int cell)
{
	if (s == e)
	{
		Seg[cell].X = x[s];
		Seg[cell].A = (x[s]*y[s])%MOD;
		Seg[cell].lgX = log(x[s]);
		Seg[cell].lgA = Seg[cell].lgX + log(y[s]);
		return;
	}
	int m = (s + e)/2;
	if (pos <= m)
		update(pos, s, m, 2*cell + 1);
	else
		update(pos, m + 1, e, 2*cell + 2);
	Seg[cell].X = (Seg[2*cell + 1].X*Seg[2*cell + 2].X)%MOD;
	Seg[cell].lgX = Seg[2*cell + 1].lgX + Seg[2*cell + 2].lgX;
	if (Seg[2*cell + 1].lgA > Seg[2*cell + 1].lgX + Seg[2*cell + 2].lgA)
	{
		Seg[cell].lgA = Seg[2*cell + 1].lgA;
		Seg[cell].A = Seg[2*cell + 1].A;
	}
	else
	{
		Seg[cell].lgA = Seg[2*cell + 1].lgX + Seg[2*cell + 2].lgA;
		Seg[cell].A = (Seg[2*cell + 1].X*Seg[2*cell + 2].A)%MOD;
	}
}
int updateX(int pos, int val)
{
	x[pos] = val;
	update(pos, 0, n - 1, 0);
	return (int) Seg[0].A;
}

int updateY(int pos, int val)
{
	y[pos] = val;
	update(pos, 0, n - 1, 0);
	return (int) Seg[0].A;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...