#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
const int MAX = 5e5 + 5, MOD = 1e9 + 7;
int n;
pii tree[4 * MAX];
int tree2[4 * MAX];
int x[MAX];
int y[MAX];
pii comb(pii a, pii b){
pii c = {0, 0};
if(a.first) c.first = 1;
if(b.first) c.first = 1;
if(1ll * a.second * b.second > 1e9) c.first = 1;
c.second = (1ll * a.second * b.second) % MOD;
return c;
}
void build(int node, int l, int r){
if(l == r){
tree[node] = {0, x[l]};
return;
}
int mid = (l + r) / 2;
build(2 * node, l, mid);
build(2 * node + 1, mid + 1, r);
tree[node] = comb(tree[2 * node], tree[2 * node + 1]);
}
void updatex(int node, int l, int r, int pos, int val){
if(l == r){
tree[node] = {0, val};
return;
}
int mid = (l + r) / 2;
if(pos <= mid){
updatex(2 * node, l, mid, pos, val);
}
else{
updatex(2 * node + 1, mid + 1, r, pos, val);
}
tree[node] = comb(tree[2 * node], tree[2 * node + 1]);
}
pii mult(int node, int l, int r, int ql, int qr){
if(qr < l || r < ql) return {0, 1};
if(ql <= l && r <= qr) return tree[node];
int mid = (l + r) / 2;
return comb(mult(2 * node, l, mid, ql, qr), mult(2 * node + 1, mid + 1, r, ql, qr));
}
int comb2(int a, int b){
if(b > a) swap(a, b);
pii m = mult(1, 0, n - 1, b + 1, a);
if(m.first) return a;
if(1ll * m.second * y[a] > y[b]) return a;
return b;
}
void build2(int node, int l, int r){
if(l == r){
tree2[node] = l;
return;
}
int mid = (l + r) / 2;
build2(2 * node, l, mid);
build2(2 * node + 1, mid + 1, r);
tree2[node] = comb2(tree2[2 * node], tree2[2 * node + 1]);
}
void updatey(int node, int l, int r, int pos){
if(l == r) return;
int mid = (l + r) / 2;
if(pos <= mid){
updatey(2 * node, l, mid, pos);
}
else{
updatey(2 * node + 1, mid + 1, r, pos);
}
tree2[node] = comb2(tree2[2 * node], tree2[2 * node + 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);
build2(1, 0, n - 1);
int id = tree2[1];
return 1ll * mult(1, 0, n - 1, 0, id).second * y[id] % MOD;
}
int updateX(int pos, int val) {
x[pos] = val;
updatex(1, 0, n - 1, pos, val);
updatey(1, 0, n - 1, pos);
int id = tree2[1];
return 1ll * mult(1, 0, n - 1, 0, id).second * y[id] % MOD;
}
int updateY(int pos, int val) {
y[pos] = val;
updatey(1, 0, n - 1, pos);
int id = tree2[1];
return 1ll * mult(1, 0, n - 1, 0, id).second * y[id] % MOD;
}
Compilation message
horses.cpp: In function 'std::pair<int, int> comb(std::pair<int, int>, std::pair<int, int>)':
horses.cpp:22:44: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
22 | c.second = (1ll * a.second * b.second) % MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:99:58: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
99 | return 1ll * mult(1, 0, n - 1, 0, id).second * y[id] % MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:107:58: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
107 | return 1ll * mult(1, 0, n - 1, 0, id).second * y[id] % MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:114:58: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
114 | return 1ll * mult(1, 0, n - 1, 0, id).second * y[id] % MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6744 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6584 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6488 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6488 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
3 ms |
6492 KB |
Output is correct |
24 |
Correct |
3 ms |
6488 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
3 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6488 KB |
Output is correct |
29 |
Correct |
3 ms |
6492 KB |
Output is correct |
30 |
Correct |
2 ms |
6492 KB |
Output is correct |
31 |
Correct |
2 ms |
6492 KB |
Output is correct |
32 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
438 ms |
28124 KB |
Output is correct |
2 |
Correct |
406 ms |
36492 KB |
Output is correct |
3 |
Correct |
516 ms |
27692 KB |
Output is correct |
4 |
Correct |
500 ms |
31440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6488 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
3 ms |
6492 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6636 KB |
Output is correct |
27 |
Correct |
3 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
3 ms |
6492 KB |
Output is correct |
30 |
Correct |
2 ms |
6492 KB |
Output is correct |
31 |
Correct |
3 ms |
6596 KB |
Output is correct |
32 |
Correct |
3 ms |
6488 KB |
Output is correct |
33 |
Correct |
190 ms |
26988 KB |
Output is correct |
34 |
Correct |
183 ms |
26968 KB |
Output is correct |
35 |
Correct |
181 ms |
33844 KB |
Output is correct |
36 |
Correct |
160 ms |
33900 KB |
Output is correct |
37 |
Correct |
186 ms |
25172 KB |
Output is correct |
38 |
Correct |
158 ms |
26192 KB |
Output is correct |
39 |
Correct |
177 ms |
24912 KB |
Output is correct |
40 |
Correct |
161 ms |
28756 KB |
Output is correct |
41 |
Correct |
173 ms |
25540 KB |
Output is correct |
42 |
Correct |
177 ms |
25084 KB |
Output is correct |
43 |
Correct |
128 ms |
29360 KB |
Output is correct |
44 |
Correct |
128 ms |
29348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6728 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
3 ms |
6492 KB |
Output is correct |
24 |
Correct |
3 ms |
6492 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
3 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
3 ms |
6492 KB |
Output is correct |
30 |
Correct |
2 ms |
6744 KB |
Output is correct |
31 |
Correct |
2 ms |
6492 KB |
Output is correct |
32 |
Correct |
3 ms |
6492 KB |
Output is correct |
33 |
Correct |
444 ms |
27820 KB |
Output is correct |
34 |
Correct |
405 ms |
36476 KB |
Output is correct |
35 |
Correct |
505 ms |
27728 KB |
Output is correct |
36 |
Correct |
492 ms |
31592 KB |
Output is correct |
37 |
Correct |
193 ms |
26916 KB |
Output is correct |
38 |
Correct |
192 ms |
27220 KB |
Output is correct |
39 |
Correct |
174 ms |
33872 KB |
Output is correct |
40 |
Correct |
160 ms |
33876 KB |
Output is correct |
41 |
Correct |
196 ms |
25164 KB |
Output is correct |
42 |
Correct |
149 ms |
26100 KB |
Output is correct |
43 |
Correct |
177 ms |
24912 KB |
Output is correct |
44 |
Correct |
168 ms |
29008 KB |
Output is correct |
45 |
Correct |
171 ms |
24916 KB |
Output is correct |
46 |
Correct |
174 ms |
25072 KB |
Output is correct |
47 |
Correct |
129 ms |
29360 KB |
Output is correct |
48 |
Correct |
129 ms |
29268 KB |
Output is correct |
49 |
Correct |
774 ms |
29308 KB |
Output is correct |
50 |
Correct |
690 ms |
29008 KB |
Output is correct |
51 |
Correct |
482 ms |
35668 KB |
Output is correct |
52 |
Correct |
344 ms |
35140 KB |
Output is correct |
53 |
Correct |
787 ms |
27476 KB |
Output is correct |
54 |
Correct |
438 ms |
27772 KB |
Output is correct |
55 |
Correct |
707 ms |
25924 KB |
Output is correct |
56 |
Correct |
551 ms |
31060 KB |
Output is correct |
57 |
Correct |
653 ms |
26704 KB |
Output is correct |
58 |
Correct |
705 ms |
27244 KB |
Output is correct |
59 |
Correct |
137 ms |
29360 KB |
Output is correct |