#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 time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
2 ms |
564 KB |
Output is correct |
6 |
Correct |
2 ms |
564 KB |
Output is correct |
7 |
Correct |
2 ms |
572 KB |
Output is correct |
8 |
Correct |
2 ms |
572 KB |
Output is correct |
9 |
Correct |
2 ms |
572 KB |
Output is correct |
10 |
Correct |
2 ms |
572 KB |
Output is correct |
11 |
Correct |
2 ms |
572 KB |
Output is correct |
12 |
Correct |
2 ms |
572 KB |
Output is correct |
13 |
Correct |
2 ms |
572 KB |
Output is correct |
14 |
Correct |
2 ms |
636 KB |
Output is correct |
15 |
Correct |
2 ms |
636 KB |
Output is correct |
16 |
Correct |
2 ms |
636 KB |
Output is correct |
17 |
Correct |
2 ms |
636 KB |
Output is correct |
18 |
Correct |
2 ms |
636 KB |
Output is correct |
19 |
Correct |
2 ms |
636 KB |
Output is correct |
20 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
636 KB |
Output is correct |
2 |
Correct |
2 ms |
636 KB |
Output is correct |
3 |
Correct |
2 ms |
636 KB |
Output is correct |
4 |
Correct |
2 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
636 KB |
Output is correct |
11 |
Correct |
2 ms |
636 KB |
Output is correct |
12 |
Correct |
2 ms |
636 KB |
Output is correct |
13 |
Correct |
2 ms |
636 KB |
Output is correct |
14 |
Correct |
2 ms |
636 KB |
Output is correct |
15 |
Correct |
2 ms |
636 KB |
Output is correct |
16 |
Correct |
2 ms |
636 KB |
Output is correct |
17 |
Correct |
2 ms |
636 KB |
Output is correct |
18 |
Correct |
2 ms |
636 KB |
Output is correct |
19 |
Correct |
2 ms |
636 KB |
Output is correct |
20 |
Correct |
2 ms |
636 KB |
Output is correct |
21 |
Correct |
2 ms |
636 KB |
Output is correct |
22 |
Correct |
2 ms |
636 KB |
Output is correct |
23 |
Correct |
2 ms |
800 KB |
Output is correct |
24 |
Correct |
2 ms |
836 KB |
Output is correct |
25 |
Correct |
3 ms |
836 KB |
Output is correct |
26 |
Correct |
2 ms |
836 KB |
Output is correct |
27 |
Correct |
2 ms |
836 KB |
Output is correct |
28 |
Correct |
2 ms |
948 KB |
Output is correct |
29 |
Correct |
2 ms |
948 KB |
Output is correct |
30 |
Correct |
2 ms |
948 KB |
Output is correct |
31 |
Correct |
2 ms |
948 KB |
Output is correct |
32 |
Correct |
2 ms |
948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
46460 KB |
Output is correct |
2 |
Correct |
224 ms |
46460 KB |
Output is correct |
3 |
Correct |
176 ms |
50368 KB |
Output is correct |
4 |
Correct |
206 ms |
57992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
57992 KB |
Output is correct |
2 |
Correct |
2 ms |
57992 KB |
Output is correct |
3 |
Correct |
2 ms |
57992 KB |
Output is correct |
4 |
Correct |
2 ms |
57992 KB |
Output is correct |
5 |
Correct |
2 ms |
57992 KB |
Output is correct |
6 |
Correct |
2 ms |
57992 KB |
Output is correct |
7 |
Correct |
2 ms |
57992 KB |
Output is correct |
8 |
Correct |
2 ms |
57992 KB |
Output is correct |
9 |
Correct |
2 ms |
57992 KB |
Output is correct |
10 |
Correct |
2 ms |
57992 KB |
Output is correct |
11 |
Correct |
2 ms |
57992 KB |
Output is correct |
12 |
Correct |
2 ms |
57992 KB |
Output is correct |
13 |
Correct |
2 ms |
57992 KB |
Output is correct |
14 |
Correct |
2 ms |
57992 KB |
Output is correct |
15 |
Correct |
2 ms |
57992 KB |
Output is correct |
16 |
Correct |
2 ms |
57992 KB |
Output is correct |
17 |
Correct |
2 ms |
57992 KB |
Output is correct |
18 |
Correct |
2 ms |
57992 KB |
Output is correct |
19 |
Correct |
2 ms |
57992 KB |
Output is correct |
20 |
Correct |
2 ms |
57992 KB |
Output is correct |
21 |
Correct |
2 ms |
57992 KB |
Output is correct |
22 |
Correct |
2 ms |
57992 KB |
Output is correct |
23 |
Correct |
2 ms |
57992 KB |
Output is correct |
24 |
Correct |
3 ms |
57992 KB |
Output is correct |
25 |
Correct |
2 ms |
57992 KB |
Output is correct |
26 |
Correct |
2 ms |
57992 KB |
Output is correct |
27 |
Correct |
2 ms |
57992 KB |
Output is correct |
28 |
Correct |
2 ms |
57992 KB |
Output is correct |
29 |
Correct |
2 ms |
57992 KB |
Output is correct |
30 |
Correct |
2 ms |
57992 KB |
Output is correct |
31 |
Correct |
2 ms |
57992 KB |
Output is correct |
32 |
Correct |
2 ms |
57992 KB |
Output is correct |
33 |
Correct |
88 ms |
61132 KB |
Output is correct |
34 |
Correct |
91 ms |
65072 KB |
Output is correct |
35 |
Correct |
110 ms |
76040 KB |
Output is correct |
36 |
Correct |
111 ms |
86908 KB |
Output is correct |
37 |
Correct |
61 ms |
88916 KB |
Output is correct |
38 |
Correct |
83 ms |
91908 KB |
Output is correct |
39 |
Correct |
55 ms |
93868 KB |
Output is correct |
40 |
Correct |
85 ms |
99916 KB |
Output is correct |
41 |
Correct |
71 ms |
101880 KB |
Output is correct |
42 |
Correct |
71 ms |
104052 KB |
Output is correct |
43 |
Correct |
79 ms |
110396 KB |
Output is correct |
44 |
Correct |
79 ms |
116764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
116764 KB |
Output is correct |
2 |
Correct |
2 ms |
116764 KB |
Output is correct |
3 |
Correct |
2 ms |
116764 KB |
Output is correct |
4 |
Correct |
2 ms |
116764 KB |
Output is correct |
5 |
Correct |
2 ms |
116764 KB |
Output is correct |
6 |
Correct |
2 ms |
116764 KB |
Output is correct |
7 |
Correct |
2 ms |
116764 KB |
Output is correct |
8 |
Correct |
2 ms |
116764 KB |
Output is correct |
9 |
Correct |
2 ms |
116764 KB |
Output is correct |
10 |
Correct |
2 ms |
116764 KB |
Output is correct |
11 |
Correct |
2 ms |
116764 KB |
Output is correct |
12 |
Correct |
2 ms |
116764 KB |
Output is correct |
13 |
Correct |
1 ms |
116764 KB |
Output is correct |
14 |
Correct |
2 ms |
116764 KB |
Output is correct |
15 |
Correct |
2 ms |
116764 KB |
Output is correct |
16 |
Correct |
2 ms |
116764 KB |
Output is correct |
17 |
Correct |
2 ms |
116764 KB |
Output is correct |
18 |
Correct |
2 ms |
116764 KB |
Output is correct |
19 |
Correct |
2 ms |
116764 KB |
Output is correct |
20 |
Correct |
2 ms |
116764 KB |
Output is correct |
21 |
Correct |
2 ms |
116764 KB |
Output is correct |
22 |
Correct |
2 ms |
116764 KB |
Output is correct |
23 |
Correct |
2 ms |
116764 KB |
Output is correct |
24 |
Correct |
3 ms |
116764 KB |
Output is correct |
25 |
Correct |
2 ms |
116764 KB |
Output is correct |
26 |
Correct |
2 ms |
116764 KB |
Output is correct |
27 |
Correct |
3 ms |
116764 KB |
Output is correct |
28 |
Correct |
2 ms |
116764 KB |
Output is correct |
29 |
Correct |
2 ms |
116764 KB |
Output is correct |
30 |
Correct |
2 ms |
116764 KB |
Output is correct |
31 |
Correct |
2 ms |
116764 KB |
Output is correct |
32 |
Correct |
2 ms |
116764 KB |
Output is correct |
33 |
Correct |
107 ms |
121808 KB |
Output is correct |
34 |
Correct |
227 ms |
134436 KB |
Output is correct |
35 |
Correct |
179 ms |
138108 KB |
Output is correct |
36 |
Correct |
207 ms |
145856 KB |
Output is correct |
37 |
Correct |
89 ms |
148764 KB |
Output is correct |
38 |
Correct |
88 ms |
152736 KB |
Output is correct |
39 |
Correct |
110 ms |
163620 KB |
Output is correct |
40 |
Correct |
117 ms |
174456 KB |
Output is correct |
41 |
Correct |
63 ms |
176528 KB |
Output is correct |
42 |
Correct |
84 ms |
179540 KB |
Output is correct |
43 |
Correct |
56 ms |
181588 KB |
Output is correct |
44 |
Correct |
89 ms |
187548 KB |
Output is correct |
45 |
Correct |
63 ms |
189568 KB |
Output is correct |
46 |
Correct |
55 ms |
191704 KB |
Output is correct |
47 |
Correct |
79 ms |
198136 KB |
Output is correct |
48 |
Correct |
78 ms |
204504 KB |
Output is correct |
49 |
Correct |
208 ms |
210484 KB |
Output is correct |
50 |
Correct |
191 ms |
215524 KB |
Output is correct |
51 |
Correct |
155 ms |
227288 KB |
Output is correct |
52 |
Correct |
159 ms |
238672 KB |
Output is correct |
53 |
Correct |
166 ms |
242108 KB |
Output is correct |
54 |
Correct |
146 ms |
246028 KB |
Output is correct |
55 |
Correct |
92 ms |
248200 KB |
Output is correct |
56 |
Correct |
125 ms |
255812 KB |
Output is correct |
57 |
Correct |
98 ms |
258552 KB |
Output is correct |
58 |
Correct |
103 ms |
261876 KB |
Output is correct |
59 |
Correct |
82 ms |
267400 KB |
Output is correct |