#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
class segtree{
public:
struct nodes{
double clogx, clogy;
double logx;
long long X;
long long cX, cY;
};
vector<long long> X, Y;
vector<nodes> tree;
long long N;
long long MOD = 1e9 + 7;
nodes comp(nodes a, nodes b){
nodes c = a;
c.logx += b.logx;
c.X = c.X * b.X % MOD;
if(a.clogy + a.clogx < a.logx + b.clogx + b.clogy){
c.clogy = b.clogy;
c.clogx = a.logx + b.clogx;
c.cX = a.X * b.cX % MOD;
c.cY = b.cY;
}
return c;
}
void init(long long NN){
X.assign(NN, 0);
Y.assign(NN, 0);
long long K = 1;
while(K <= NN) K *= 2;
N = K;
tree.assign(K * 2, {0, 0, 0, 0, 0, 0});
}
void add(int node, int l, int r, int pos){
if(pos < l || pos >= r){
return;
}
if(r - l == 1){
tree[node].X = X[pos];
tree[node].cX = X[pos];
tree[node].cY = Y[pos];
tree[node].logx = log((double)(X[pos]));
tree[node].clogx = log((double)(X[pos]));
tree[node].clogy = log((double)(Y[pos]));
return;
}
int mid = (l + r) / 2;
if(pos < mid){
add(node * 2 + 1, l, mid, pos);
}
else{
add(node * 2 + 2, mid, r, pos);
}
tree[node] = comp(tree[node * 2 + 1], tree[node * 2 + 2]);
}
void add(int pos){
add(0, 0, N, pos);
}
long long ans(){
return tree[0].cX * tree[0].cY % MOD;
}
};
segtree tree;
int init(int NN, int XX[], int YY[]){
int N = NN;
tree.init(N);
for(int i = 0; i < N; i ++){
tree.X[i] = XX[i];
tree.Y[i] = YY[i];
tree.add(i);
}
return tree.ans();
}
int updateX(int pos, int val){
tree.X[pos] = val;
tree.add(pos);
return tree.ans();
}
int updateY(int pos, int val){
tree.Y[pos] = val;
tree.add(pos);
return tree.ans();
}
Compilation message
horses.cpp: In member function 'void segtree::add(int)':
horses.cpp:59:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
59 | add(0, 0, N, pos);
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:74:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
74 | return tree.ans();
| ~~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:79:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
79 | return tree.ans();
| ~~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:84:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
84 | return tree.ans();
| ~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
187 ms |
62188 KB |
Output is correct |
2 |
Correct |
277 ms |
62228 KB |
Output is correct |
3 |
Correct |
250 ms |
62260 KB |
Output is correct |
4 |
Correct |
257 ms |
62408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
154 ms |
61372 KB |
Output is correct |
34 |
Correct |
158 ms |
61376 KB |
Output is correct |
35 |
Correct |
198 ms |
61420 KB |
Output is correct |
36 |
Correct |
194 ms |
61420 KB |
Output is correct |
37 |
Correct |
135 ms |
61380 KB |
Output is correct |
38 |
Correct |
162 ms |
61388 KB |
Output is correct |
39 |
Correct |
128 ms |
61344 KB |
Output is correct |
40 |
Correct |
177 ms |
61420 KB |
Output is correct |
41 |
Correct |
130 ms |
61348 KB |
Output is correct |
42 |
Correct |
130 ms |
61328 KB |
Output is correct |
43 |
Correct |
180 ms |
61412 KB |
Output is correct |
44 |
Correct |
169 ms |
61396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
198 ms |
62164 KB |
Output is correct |
34 |
Correct |
274 ms |
62268 KB |
Output is correct |
35 |
Correct |
239 ms |
62300 KB |
Output is correct |
36 |
Correct |
260 ms |
62316 KB |
Output is correct |
37 |
Correct |
155 ms |
61376 KB |
Output is correct |
38 |
Correct |
155 ms |
61380 KB |
Output is correct |
39 |
Correct |
193 ms |
61512 KB |
Output is correct |
40 |
Correct |
188 ms |
61424 KB |
Output is correct |
41 |
Correct |
133 ms |
61340 KB |
Output is correct |
42 |
Correct |
165 ms |
61380 KB |
Output is correct |
43 |
Correct |
129 ms |
61344 KB |
Output is correct |
44 |
Correct |
189 ms |
61416 KB |
Output is correct |
45 |
Correct |
131 ms |
61352 KB |
Output is correct |
46 |
Correct |
131 ms |
61460 KB |
Output is correct |
47 |
Correct |
170 ms |
61416 KB |
Output is correct |
48 |
Correct |
169 ms |
61364 KB |
Output is correct |
49 |
Correct |
227 ms |
62272 KB |
Output is correct |
50 |
Correct |
269 ms |
62284 KB |
Output is correct |
51 |
Correct |
222 ms |
62376 KB |
Output is correct |
52 |
Correct |
232 ms |
62412 KB |
Output is correct |
53 |
Correct |
205 ms |
62252 KB |
Output is correct |
54 |
Correct |
221 ms |
62160 KB |
Output is correct |
55 |
Correct |
157 ms |
61488 KB |
Output is correct |
56 |
Correct |
214 ms |
62348 KB |
Output is correct |
57 |
Correct |
159 ms |
62268 KB |
Output is correct |
58 |
Correct |
161 ms |
62408 KB |
Output is correct |
59 |
Correct |
170 ms |
61312 KB |
Output is correct |