#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
const int mod = 1e9+7;
const int maxn = 500005;
struct node {
double logsum;
double bestlogsum;
ll mult;
ll bestmult;
};
int n;
node st[4*maxn];
ll x[maxn], y[maxn];
void combine(int v, int l, int r){
st[v].logsum = st[l].logsum + st[r].logsum;
st[v].mult = (st[l].mult * st[r].mult) % mod;
if(st[l].bestlogsum > st[l].logsum + st[r].bestlogsum){
st[v].bestlogsum = st[l].bestlogsum;
st[v].bestmult = st[l].bestmult;
} else {
st[v].bestlogsum = st[l].logsum + st[r].bestlogsum;
st[v].bestmult = (st[l].mult * st[r].bestmult) % mod;
}
}
void build(int v, int tl, int tr){
if(tl == tr){
st[v].logsum = log10(x[tl]);
st[v].mult = x[tl];
st[v].bestlogsum = st[v].logsum + log10(y[tl]);
st[v].bestmult = (st[v].mult * y[tl]) % mod;
} else {
int tm = (tl+tr)/2;
build(v*2, tl, tm);
build(v*2+1, tm+1, tr);
combine(v, v*2, v*2+1);
}
}
void update(int v, int tl, int tr, int pos, int val){
if(tl == tr){
st[v].logsum = log10(x[tl]);
st[v].mult = x[tl];
st[v].bestlogsum = st[v].logsum + log10(y[tl]);
st[v].bestmult = (st[v].mult * y[tl]) % mod;
} else {
int tm = (tl+tr)/2;
if(pos <= tm)
update(v*2, tl, tm, pos, val);
else
update(v*2+1, tm+1, tr, pos, val);
combine(v, v*2, v*2+1);
}
}
int init(int N, int X[], int Y[]){
n = N;
for(int i = 0; i < N; i++){
x[i] = X[i];
y[i] = Y[i];
}
build(1, 0, n-1);
return st[1].bestmult;
}
int updateX(int pos, int val){
x[pos] = val;
update(1, 0, n-1, pos, val);
return st[1].bestmult;
}
int updateY(int pos, int val){
y[pos] = val;
update(1, 0, n-1, pos, val);
return st[1].bestmult;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:79:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
79 | return st[1].bestmult;
| ~~~~~~^~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:85:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
85 | return st[1].bestmult;
| ~~~~~~^~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:91:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
91 | return st[1].bestmult;
| ~~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
228 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 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 |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
49616 KB |
Output is correct |
2 |
Correct |
176 ms |
58484 KB |
Output is correct |
3 |
Correct |
136 ms |
49632 KB |
Output is correct |
4 |
Correct |
157 ms |
53508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
216 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
308 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 |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
65 ms |
48824 KB |
Output is correct |
34 |
Correct |
68 ms |
48836 KB |
Output is correct |
35 |
Correct |
91 ms |
55812 KB |
Output is correct |
36 |
Correct |
90 ms |
55664 KB |
Output is correct |
37 |
Correct |
46 ms |
46976 KB |
Output is correct |
38 |
Correct |
59 ms |
47940 KB |
Output is correct |
39 |
Correct |
44 ms |
46856 KB |
Output is correct |
40 |
Correct |
61 ms |
50764 KB |
Output is correct |
41 |
Correct |
40 ms |
46984 KB |
Output is correct |
42 |
Correct |
42 ms |
46980 KB |
Output is correct |
43 |
Correct |
60 ms |
51156 KB |
Output is correct |
44 |
Correct |
64 ms |
51252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
0 ms |
312 KB |
Output is correct |
18 |
Correct |
1 ms |
312 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 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 |
320 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 |
77 ms |
49672 KB |
Output is correct |
34 |
Correct |
172 ms |
58340 KB |
Output is correct |
35 |
Correct |
125 ms |
49616 KB |
Output is correct |
36 |
Correct |
149 ms |
53408 KB |
Output is correct |
37 |
Correct |
61 ms |
48832 KB |
Output is correct |
38 |
Correct |
62 ms |
48804 KB |
Output is correct |
39 |
Correct |
83 ms |
55872 KB |
Output is correct |
40 |
Correct |
88 ms |
55788 KB |
Output is correct |
41 |
Correct |
48 ms |
47068 KB |
Output is correct |
42 |
Correct |
55 ms |
47860 KB |
Output is correct |
43 |
Correct |
40 ms |
46932 KB |
Output is correct |
44 |
Correct |
82 ms |
50832 KB |
Output is correct |
45 |
Correct |
46 ms |
46956 KB |
Output is correct |
46 |
Correct |
41 ms |
47052 KB |
Output is correct |
47 |
Correct |
58 ms |
51212 KB |
Output is correct |
48 |
Correct |
58 ms |
51140 KB |
Output is correct |
49 |
Correct |
143 ms |
50804 KB |
Output is correct |
50 |
Correct |
137 ms |
50892 KB |
Output is correct |
51 |
Correct |
127 ms |
57708 KB |
Output is correct |
52 |
Correct |
111 ms |
57156 KB |
Output is correct |
53 |
Correct |
127 ms |
49152 KB |
Output is correct |
54 |
Correct |
98 ms |
49692 KB |
Output is correct |
55 |
Correct |
90 ms |
47976 KB |
Output is correct |
56 |
Correct |
96 ms |
52612 KB |
Output is correct |
57 |
Correct |
72 ms |
48664 KB |
Output is correct |
58 |
Correct |
82 ms |
49032 KB |
Output is correct |
59 |
Correct |
61 ms |
51244 KB |
Output is correct |