#include <bits/stdc++.h>
using namespace std;
using ld = long double;
const int mod = 1e9 + 7;
void addSelf(int &x, const int &y) {
x += y;
if (x >= mod) {
x -= mod;
}
}
int add(int x, const int &y) {
addSelf(x, y);
return x;
}
void multSelf(int &x, const int &y) {
x = (int64_t)x * y % mod;
}
int mult(int x, const int &y) {
multSelf(x, y);
return x;
}
int Pow(int x, int n) {
int ans = 1;
while (n) {
if (n & 1) {
multSelf(ans, x);
}
multSelf(x, x);
n >>= 1;
}
return ans;
}
int invers(int x) {
return Pow(x, mod - 2);
}
struct node {
ld maxSum, lazySum;
int maxProd, lazyProd;
node operator + (const node &rhs) const {
node ret;
ret.maxSum = max(maxSum, rhs.maxSum);
if (maxSum == ret.maxSum) {
ret.maxProd = maxProd;
} else {
ret.maxProd = rhs.maxProd;
}
ret.lazySum = 0;
ret.lazyProd = 1;
return ret;
};
};
const int kN = 5e5;
int n, Prod = 1, A[1 + kN], B[1 + kN];
ld Sum;
struct ST {
vector<node> t;
void init() {
int dim = 1;
while (dim < n) {
dim *= 2;
}
t.resize(dim * 2);
}
void build(int x, int lx, int rx) {
if (lx == rx) {
Sum += log(A[lx]);
multSelf(Prod, A[lx]);
t[x] = {Sum + log(B[lx]), 0, mult(Prod, B[lx]), 1};
return;
}
int mid = (lx + rx) / 2;
build(x * 2, lx, mid);
build(x * 2 + 1, mid + 1, rx);
t[x] = t[x * 2] + t[x * 2 + 1];
}
void updateNode(int x, ld lazySum, int lazyProd) {
t[x].maxSum += lazySum;
t[x].lazySum += lazySum;
multSelf(t[x].maxProd, lazyProd);
multSelf(t[x].lazyProd, lazyProd);
}
void push(int x) {
for (int i = 0; i < 2; ++i) {
updateNode(x * 2 + i, t[x].lazySum, t[x].lazyProd);
}
t[x].lazySum = 0;
t[x].lazyProd = 1;
}
void update(int x, int lx, int rx, int st, int dr, ld lazySum, int lazyProd) {
if (st <= lx && rx <= dr) {
updateNode(x, lazySum, lazyProd);
return;
}
push(x);
int mid = (lx + rx) / 2;
if (st <= mid) {
update(x * 2, lx, mid, st, dr, lazySum, lazyProd);
}
if (mid < dr) {
update(x * 2 + 1, mid + 1, rx, st, dr, lazySum, lazyProd);
}
t[x] = t[x * 2] + t[x * 2 + 1];
}
void update(int st, int dr, ld lazySum, int lazyProd) {
update(1, 1, n, st, dr, lazySum, lazyProd);
}
} t;
int init(int N, int X[], int Y[]) {
n = N;
for (int i = 1; i <= n; ++i) {
A[i] = X[i - 1];
B[i] = Y[i - 1];
}
t.init();
t.build(1, 1, n);
return t.t[1].maxProd;
}
int updateX(int pos, int val) {
pos += 1;
t.update(pos, n, log(val) - log(A[pos]), mult(invers(A[pos]), val));
A[pos] = val;
return t.t[1].maxProd;
}
int updateY(int pos, int val) {
pos += 1;
t.update(pos, pos, log(val) - log(B[pos]), mult(invers(B[pos]), val));
B[pos] = val;
return t.t[1].maxProd;
}
Compilation message
horses.cpp: In function 'void multSelf(int&, const int&)':
horses.cpp:21:22: warning: conversion from 'int64_t' {aka 'long int'} to 'int' may change value [-Wconversion]
21 | x = (int64_t)x * y % mod;
| ~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
448 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
440 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
58956 KB |
Output is correct |
2 |
Correct |
268 ms |
59116 KB |
Output is correct |
3 |
Correct |
223 ms |
59192 KB |
Output is correct |
4 |
Correct |
229 ms |
59148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
86 ms |
58352 KB |
Output is correct |
34 |
Correct |
84 ms |
58260 KB |
Output is correct |
35 |
Correct |
97 ms |
58356 KB |
Output is correct |
36 |
Correct |
99 ms |
58288 KB |
Output is correct |
37 |
Correct |
73 ms |
58308 KB |
Output is correct |
38 |
Correct |
72 ms |
58244 KB |
Output is correct |
39 |
Correct |
62 ms |
58228 KB |
Output is correct |
40 |
Correct |
83 ms |
58320 KB |
Output is correct |
41 |
Correct |
61 ms |
58316 KB |
Output is correct |
42 |
Correct |
61 ms |
58308 KB |
Output is correct |
43 |
Correct |
73 ms |
58352 KB |
Output is correct |
44 |
Correct |
72 ms |
58164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
440 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
448 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
156 ms |
59112 KB |
Output is correct |
34 |
Correct |
248 ms |
58968 KB |
Output is correct |
35 |
Correct |
243 ms |
58948 KB |
Output is correct |
36 |
Correct |
236 ms |
58932 KB |
Output is correct |
37 |
Correct |
86 ms |
57924 KB |
Output is correct |
38 |
Correct |
86 ms |
57948 KB |
Output is correct |
39 |
Correct |
99 ms |
57960 KB |
Output is correct |
40 |
Correct |
104 ms |
57896 KB |
Output is correct |
41 |
Correct |
70 ms |
57944 KB |
Output is correct |
42 |
Correct |
73 ms |
57908 KB |
Output is correct |
43 |
Correct |
62 ms |
57876 KB |
Output is correct |
44 |
Correct |
81 ms |
57956 KB |
Output is correct |
45 |
Correct |
60 ms |
57932 KB |
Output is correct |
46 |
Correct |
64 ms |
58016 KB |
Output is correct |
47 |
Correct |
72 ms |
57828 KB |
Output is correct |
48 |
Correct |
73 ms |
57884 KB |
Output is correct |
49 |
Correct |
232 ms |
58624 KB |
Output is correct |
50 |
Correct |
237 ms |
58660 KB |
Output is correct |
51 |
Correct |
182 ms |
58692 KB |
Output is correct |
52 |
Correct |
185 ms |
58568 KB |
Output is correct |
53 |
Correct |
217 ms |
58564 KB |
Output is correct |
54 |
Correct |
162 ms |
58500 KB |
Output is correct |
55 |
Correct |
140 ms |
57796 KB |
Output is correct |
56 |
Correct |
176 ms |
58656 KB |
Output is correct |
57 |
Correct |
150 ms |
58564 KB |
Output is correct |
58 |
Correct |
157 ms |
58596 KB |
Output is correct |
59 |
Correct |
73 ms |
57404 KB |
Output is correct |