#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int mul(int a, int b) {
if (a > mod / b) {
return mod;
}
else {
return a * b;
}
}
struct node {
int best;
int prod1;
int prod2;
};
const int maxN = 5e5 + 20;
node tree[maxN * 4];
int X[maxN];
int Y[maxN];
int N;
int get(int id, int lt, int rt, int ql, int qr, int type) {
if (lt == ql && rt == qr) {
if (type == 1) {
return tree[id].prod1;
}
else {
return tree[id].prod2;
}
}
int mt = (lt + rt) / 2;
if (qr <= mt) {
return get(id * 2, lt, mt, ql, qr, type);
}
else if (ql >= mt + 1) {
return get(id * 2 + 1, mt + 1, rt, ql, qr, type);
}
else {
if (type == 1) {
return mul(get(id * 2, lt, mt, ql, mt, type), get(id * 2 + 1, mt + 1, rt, mt + 1, qr, type));
}
else {
return 1LL * get(id * 2, lt, mt, ql, mt, type) * get(id * 2 + 1, mt + 1, rt, mt + 1, qr, type) % mod;
}
}
}
void merge(int id, int type) {
if (type == 1) {
tree[id].prod1 = mul(tree[id * 2].prod1, tree[id * 2 + 1].prod1);
tree[id].prod2 = 1LL * tree[id * 2].prod2 * tree[id * 2 + 1].prod2 % mod;
}
else {
int best_l = tree[id * 2].best;
int best_r = tree[id * 2 + 1].best;
if (mul(get(1, 1, N, best_l + 1, best_r, 1), Y[best_r]) > Y[best_l]) {
tree[id].best = best_r;
}
else {
tree[id].best = best_l;
}
}
}
void build(int id, int lt, int rt, int type) {
if (lt == rt) {
if (type == 1) {
tree[id].prod1 = X[lt];
tree[id].prod2 = X[lt];
}
else {
tree[id].best = lt;
}
return;
}
int mt = (lt + rt) / 2;
build(id * 2, lt, mt, type);
build(id * 2 + 1, mt + 1, rt, type);
merge(id, type);
}
void update(int id, int lt, int rt, int pos, int type) {
if (lt == rt) {
if (type == 1) {
tree[id].prod1 = X[lt];
tree[id].prod2 = X[lt];
}
else {
tree[id].best = lt;
}
return;
}
int mt = (lt + rt) / 2;
if (pos <= mt) {
update(id * 2, lt, mt, pos, type);
}
else {
update(id * 2 + 1, mt + 1, rt, pos, type);
}
merge(id, type);
}
int calc() {
return 1LL * get(1, 1, N, 1, tree[1].best, 2) * Y[tree[1].best] % mod;
}
int init(int _N, int _X[], int _Y[]) {
N = _N;
for (int i = 1; i <= N; i++) {
X[i] = _X[i - 1];
Y[i] = _Y[i - 1];
}
build(1, 1, N, 1);
build(1, 1, N, 2);
return calc();
}
int updateX(int pos, int val) {
pos++;
X[pos] = val;
update(1, 1, N, pos, 1);
update(1, 1, N, pos, 2);
return calc();
}
int updateY(int pos, int val) {
pos++;
Y[pos] = val;
update(1, 1, N, pos, 2);
return calc();
}
Compilation message
horses.cpp: In function 'int get(int, int, int, int, int, int)':
horses.cpp:49:99: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
49 | return 1LL * get(id * 2, lt, mt, ql, mt, type) * get(id * 2 + 1, mt + 1, rt, mt + 1, qr, type) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void merge(int, int)':
horses.cpp:57:70: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
57 | tree[id].prod2 = 1LL * tree[id * 2].prod2 * tree[id * 2 + 1].prod2 % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int calc()':
horses.cpp:110:66: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
110 | return 1LL * get(1, 1, N, 1, tree[1].best, 2) * Y[tree[1].best] % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
1 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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
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 |
1 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 |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 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 |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
23092 KB |
Output is correct |
2 |
Correct |
261 ms |
33924 KB |
Output is correct |
3 |
Correct |
281 ms |
25208 KB |
Output is correct |
4 |
Correct |
330 ms |
29028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 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 |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
368 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 |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
120 ms |
20512 KB |
Output is correct |
34 |
Correct |
107 ms |
24384 KB |
Output is correct |
35 |
Correct |
98 ms |
31336 KB |
Output is correct |
36 |
Correct |
89 ms |
31312 KB |
Output is correct |
37 |
Correct |
120 ms |
22812 KB |
Output is correct |
38 |
Correct |
77 ms |
23500 KB |
Output is correct |
39 |
Correct |
91 ms |
22496 KB |
Output is correct |
40 |
Correct |
87 ms |
26356 KB |
Output is correct |
41 |
Correct |
86 ms |
22584 KB |
Output is correct |
42 |
Correct |
107 ms |
22540 KB |
Output is correct |
43 |
Correct |
69 ms |
26724 KB |
Output is correct |
44 |
Correct |
69 ms |
26832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 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 |
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 |
1 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 |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 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 |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
2 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 |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
194 ms |
23016 KB |
Output is correct |
34 |
Correct |
248 ms |
33916 KB |
Output is correct |
35 |
Correct |
293 ms |
25120 KB |
Output is correct |
36 |
Correct |
305 ms |
29068 KB |
Output is correct |
37 |
Correct |
119 ms |
24448 KB |
Output is correct |
38 |
Correct |
110 ms |
24380 KB |
Output is correct |
39 |
Correct |
109 ms |
31324 KB |
Output is correct |
40 |
Correct |
90 ms |
31276 KB |
Output is correct |
41 |
Correct |
105 ms |
22600 KB |
Output is correct |
42 |
Correct |
88 ms |
23536 KB |
Output is correct |
43 |
Correct |
92 ms |
22456 KB |
Output is correct |
44 |
Correct |
87 ms |
26440 KB |
Output is correct |
45 |
Correct |
93 ms |
22496 KB |
Output is correct |
46 |
Correct |
100 ms |
22552 KB |
Output is correct |
47 |
Correct |
70 ms |
26780 KB |
Output is correct |
48 |
Correct |
75 ms |
26816 KB |
Output is correct |
49 |
Correct |
514 ms |
26424 KB |
Output is correct |
50 |
Correct |
427 ms |
26400 KB |
Output is correct |
51 |
Correct |
243 ms |
33280 KB |
Output is correct |
52 |
Correct |
147 ms |
32748 KB |
Output is correct |
53 |
Correct |
510 ms |
24712 KB |
Output is correct |
54 |
Correct |
223 ms |
25304 KB |
Output is correct |
55 |
Correct |
410 ms |
23608 KB |
Output is correct |
56 |
Correct |
285 ms |
28236 KB |
Output is correct |
57 |
Correct |
349 ms |
24176 KB |
Output is correct |
58 |
Correct |
509 ms |
24720 KB |
Output is correct |
59 |
Correct |
68 ms |
26824 KB |
Output is correct |