Submission #28236

# Submission time Handle Problem Language Result Execution time Memory
28236 2017-07-16T03:10:50 Z RayaBurong25_1 Horses (IOI15_horses) C++14
100 / 100
193 ms 106696 KB
#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

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
1 Correct 0 ms 102784 KB Output is correct
2 Correct 0 ms 102784 KB Output is correct
3 Correct 0 ms 102784 KB Output is correct
4 Correct 0 ms 102784 KB Output is correct
5 Correct 0 ms 102784 KB Output is correct
6 Correct 0 ms 102784 KB Output is correct
7 Correct 0 ms 102784 KB Output is correct
8 Correct 0 ms 102784 KB Output is correct
9 Correct 0 ms 102784 KB Output is correct
10 Correct 0 ms 102784 KB Output is correct
11 Correct 0 ms 102784 KB Output is correct
12 Correct 0 ms 102784 KB Output is correct
13 Correct 0 ms 102784 KB Output is correct
14 Correct 0 ms 102784 KB Output is correct
15 Correct 0 ms 102784 KB Output is correct
16 Correct 0 ms 102784 KB Output is correct
17 Correct 0 ms 102784 KB Output is correct
18 Correct 0 ms 102784 KB Output is correct
19 Correct 0 ms 102784 KB Output is correct
20 Correct 0 ms 102784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 102784 KB Output is correct
2 Correct 0 ms 102784 KB Output is correct
3 Correct 0 ms 102784 KB Output is correct
4 Correct 0 ms 102784 KB Output is correct
5 Correct 0 ms 102784 KB Output is correct
6 Correct 0 ms 102784 KB Output is correct
7 Correct 0 ms 102784 KB Output is correct
8 Correct 0 ms 102784 KB Output is correct
9 Correct 0 ms 102784 KB Output is correct
10 Correct 0 ms 102784 KB Output is correct
11 Correct 0 ms 102784 KB Output is correct
12 Correct 0 ms 102784 KB Output is correct
13 Correct 0 ms 102784 KB Output is correct
14 Correct 0 ms 102784 KB Output is correct
15 Correct 0 ms 102784 KB Output is correct
16 Correct 0 ms 102784 KB Output is correct
17 Correct 0 ms 102784 KB Output is correct
18 Correct 0 ms 102784 KB Output is correct
19 Correct 0 ms 102784 KB Output is correct
20 Correct 0 ms 102784 KB Output is correct
21 Correct 0 ms 102784 KB Output is correct
22 Correct 0 ms 102784 KB Output is correct
23 Correct 0 ms 102784 KB Output is correct
24 Correct 0 ms 102784 KB Output is correct
25 Correct 0 ms 102784 KB Output is correct
26 Correct 0 ms 102784 KB Output is correct
27 Correct 0 ms 102784 KB Output is correct
28 Correct 0 ms 102784 KB Output is correct
29 Correct 0 ms 102784 KB Output is correct
30 Correct 0 ms 102784 KB Output is correct
31 Correct 0 ms 102784 KB Output is correct
32 Correct 0 ms 102784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 106696 KB Output is correct
2 Correct 173 ms 106696 KB Output is correct
3 Correct 149 ms 106696 KB Output is correct
4 Correct 193 ms 106696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 102784 KB Output is correct
2 Correct 0 ms 102784 KB Output is correct
3 Correct 0 ms 102784 KB Output is correct
4 Correct 0 ms 102784 KB Output is correct
5 Correct 0 ms 102784 KB Output is correct
6 Correct 0 ms 102784 KB Output is correct
7 Correct 0 ms 102784 KB Output is correct
8 Correct 0 ms 102784 KB Output is correct
9 Correct 0 ms 102784 KB Output is correct
10 Correct 0 ms 102784 KB Output is correct
11 Correct 0 ms 102784 KB Output is correct
12 Correct 0 ms 102784 KB Output is correct
13 Correct 0 ms 102784 KB Output is correct
14 Correct 0 ms 102784 KB Output is correct
15 Correct 0 ms 102784 KB Output is correct
16 Correct 0 ms 102784 KB Output is correct
17 Correct 0 ms 102784 KB Output is correct
18 Correct 0 ms 102784 KB Output is correct
19 Correct 0 ms 102784 KB Output is correct
20 Correct 0 ms 102784 KB Output is correct
21 Correct 0 ms 102784 KB Output is correct
22 Correct 0 ms 102784 KB Output is correct
23 Correct 0 ms 102784 KB Output is correct
24 Correct 0 ms 102784 KB Output is correct
25 Correct 0 ms 102784 KB Output is correct
26 Correct 0 ms 102784 KB Output is correct
27 Correct 0 ms 102784 KB Output is correct
28 Correct 0 ms 102784 KB Output is correct
29 Correct 0 ms 102784 KB Output is correct
30 Correct 0 ms 102784 KB Output is correct
31 Correct 0 ms 102784 KB Output is correct
32 Correct 0 ms 102784 KB Output is correct
33 Correct 63 ms 106696 KB Output is correct
34 Correct 63 ms 106696 KB Output is correct
35 Correct 76 ms 106696 KB Output is correct
36 Correct 106 ms 106696 KB Output is correct
37 Correct 36 ms 106696 KB Output is correct
38 Correct 59 ms 106696 KB Output is correct
39 Correct 19 ms 106696 KB Output is correct
40 Correct 59 ms 106696 KB Output is correct
41 Correct 19 ms 106696 KB Output is correct
42 Correct 29 ms 106696 KB Output is correct
43 Correct 56 ms 106696 KB Output is correct
44 Correct 59 ms 106696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 102784 KB Output is correct
2 Correct 0 ms 102784 KB Output is correct
3 Correct 0 ms 102784 KB Output is correct
4 Correct 0 ms 102784 KB Output is correct
5 Correct 0 ms 102784 KB Output is correct
6 Correct 0 ms 102784 KB Output is correct
7 Correct 0 ms 102784 KB Output is correct
8 Correct 0 ms 102784 KB Output is correct
9 Correct 0 ms 102784 KB Output is correct
10 Correct 0 ms 102784 KB Output is correct
11 Correct 0 ms 102784 KB Output is correct
12 Correct 0 ms 102784 KB Output is correct
13 Correct 0 ms 102784 KB Output is correct
14 Correct 0 ms 102784 KB Output is correct
15 Correct 0 ms 102784 KB Output is correct
16 Correct 0 ms 102784 KB Output is correct
17 Correct 0 ms 102784 KB Output is correct
18 Correct 0 ms 102784 KB Output is correct
19 Correct 0 ms 102784 KB Output is correct
20 Correct 0 ms 102784 KB Output is correct
21 Correct 0 ms 102784 KB Output is correct
22 Correct 0 ms 102784 KB Output is correct
23 Correct 0 ms 102784 KB Output is correct
24 Correct 0 ms 102784 KB Output is correct
25 Correct 0 ms 102784 KB Output is correct
26 Correct 0 ms 102784 KB Output is correct
27 Correct 0 ms 102784 KB Output is correct
28 Correct 0 ms 102784 KB Output is correct
29 Correct 0 ms 102784 KB Output is correct
30 Correct 0 ms 102784 KB Output is correct
31 Correct 0 ms 102784 KB Output is correct
32 Correct 0 ms 102784 KB Output is correct
33 Correct 89 ms 106696 KB Output is correct
34 Correct 189 ms 106696 KB Output is correct
35 Correct 136 ms 106696 KB Output is correct
36 Correct 193 ms 106696 KB Output is correct
37 Correct 59 ms 106696 KB Output is correct
38 Correct 66 ms 106696 KB Output is correct
39 Correct 56 ms 106696 KB Output is correct
40 Correct 109 ms 106696 KB Output is correct
41 Correct 39 ms 106696 KB Output is correct
42 Correct 76 ms 106696 KB Output is correct
43 Correct 46 ms 106696 KB Output is correct
44 Correct 59 ms 106696 KB Output is correct
45 Correct 26 ms 106696 KB Output is correct
46 Correct 16 ms 106696 KB Output is correct
47 Correct 43 ms 106696 KB Output is correct
48 Correct 56 ms 106696 KB Output is correct
49 Correct 179 ms 106696 KB Output is correct
50 Correct 169 ms 106696 KB Output is correct
51 Correct 133 ms 106696 KB Output is correct
52 Correct 133 ms 106696 KB Output is correct
53 Correct 126 ms 106696 KB Output is correct
54 Correct 103 ms 106696 KB Output is correct
55 Correct 76 ms 106696 KB Output is correct
56 Correct 113 ms 106696 KB Output is correct
57 Correct 63 ms 106696 KB Output is correct
58 Correct 49 ms 106696 KB Output is correct
59 Correct 56 ms 106696 KB Output is correct