#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
const int MOD = 1e9 + 7;
int bigmod(int b, int p) {
b %= MOD;
int res = 1;
while (p) {
if (p & 1) res = (res * b) % MOD;
p >>= 1; b = (b * b) % MOD;
}
return res;
}
int modinv(int x) {
return bigmod(x, MOD - 2);
}
const int mxN = 5e5 + 1;
int seg[4 * mxN];
pii a[mxN];
int n;
void build(int l = 1, int r = n, int idx = 1) {
if (l == r) {
seg[idx] = a[l].ss;
return;
}
int mid = (l + r) >> 1;
build(l, mid, (idx << 1));
build(mid + 1, r, (idx << 1) | 1);
seg[idx] = max(seg[(idx << 1)], seg[(idx << 1) | 1]);
}
void update(int pos, int val, int l = 1, int r = n, int idx = 1) {
if (l == r) {
seg[idx] = val;
return;
}
int mid = (l + r) >> 1;
if (pos <= mid) update(pos, val, l, mid, (idx << 1));
else update(pos, val, mid + 1, r, (idx << 1) | 1);
seg[idx] = max(seg[(idx << 1)], seg[(idx << 1) | 1]);
}
int query(int tl, int tr, int l = 1, int r = n, int idx = 1) {
if (tl <= l && r <= tr) return seg[idx];
int mid = (l + r) >> 1;
int res = -1e9;
if (tl <= mid) res = max(res, query(tl, tr, l, mid, (idx << 1)));
if (tr > mid) res = max(res, query(tl, tr, mid + 1, r, (idx << 1) | 1));
return res;
}
set<int> s;
int totmult;
int findans() {
int multi = 1;
int res = 0;
set<int>::iterator it = s.end();
while (res <= (int)(1.5e9) && it != s.begin()) {
--it;
res = (max(res, query(*it, n)) * a[*it].ff);
multi *= a[*it].ff;
}
if (it == s.begin()) res = max(res, query(1, n));
res %= MOD;
res = (res * modinv(multi)) % MOD;
res = (res * totmult) % MOD;
return res;
}
int32_t init(int32_t N, int32_t X[], int32_t Y[]) {
n = N;
totmult = 1;
s.clear();
for (int i = 1; i <= n; i++) {
a[i] = {X[i - 1], Y[i - 1]};
if (a[i].ff >= 2) {
s.insert(i);
totmult = (totmult * a[i].ff) % MOD;
}
}
build();
return findans();
}
int32_t updateX(int32_t pos, int32_t val) {
pos++;
if (a[pos].ff >= 2) {
s.erase(s.find(pos));
totmult = (totmult * modinv(a[pos].ff)) % MOD;
}
a[pos].ff = val;
if (a[pos].ff >= 2) {
s.insert(pos);
totmult = (totmult * a[pos].ff) % MOD;
}
return findans();
}
int32_t updateY(int32_t pos, int32_t val) {
pos++;
a[pos].ss = val;
update(pos, val);
return findans();
}
#undef int
Compilation message
horses.cpp: In function 'int32_t init(int32_t, int32_t*, int32_t*)':
horses.cpp:84:16: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
84 | return findans();
| ~~~~~~~^~
horses.cpp: In function 'int32_t updateX(int32_t, int32_t)':
horses.cpp:98:16: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
98 | return findans();
| ~~~~~~~^~
horses.cpp: In function 'int32_t updateY(int32_t, int32_t)':
horses.cpp:105:16: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
105 | return findans();
| ~~~~~~~^~
# |
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 |
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 |
1 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 |
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 |
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 |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
320 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 |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
320 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
293 ms |
46280 KB |
Output is correct |
2 |
Correct |
243 ms |
57280 KB |
Output is correct |
3 |
Correct |
247 ms |
48488 KB |
Output is correct |
4 |
Correct |
240 ms |
52316 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 |
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 |
1 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 |
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 |
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 |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
324 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
320 KB |
Output is correct |
30 |
Correct |
1 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
324 KB |
Output is correct |
33 |
Correct |
31 ms |
24332 KB |
Output is correct |
34 |
Correct |
31 ms |
24396 KB |
Output is correct |
35 |
Correct |
144 ms |
54696 KB |
Output is correct |
36 |
Correct |
146 ms |
54652 KB |
Output is correct |
37 |
Correct |
45 ms |
22532 KB |
Output is correct |
38 |
Correct |
72 ms |
35328 KB |
Output is correct |
39 |
Correct |
22 ms |
22304 KB |
Output is correct |
40 |
Correct |
126 ms |
49728 KB |
Output is correct |
41 |
Correct |
30 ms |
22292 KB |
Output is correct |
42 |
Correct |
36 ms |
22400 KB |
Output is correct |
43 |
Correct |
123 ms |
50096 KB |
Output is correct |
44 |
Correct |
147 ms |
50120 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 |
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 |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
344 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 |
316 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 |
320 KB |
Output is correct |
33 |
Correct |
288 ms |
48732 KB |
Output is correct |
34 |
Correct |
263 ms |
57272 KB |
Output is correct |
35 |
Correct |
245 ms |
48392 KB |
Output is correct |
36 |
Correct |
299 ms |
52372 KB |
Output is correct |
37 |
Correct |
30 ms |
24300 KB |
Output is correct |
38 |
Correct |
29 ms |
24328 KB |
Output is correct |
39 |
Correct |
153 ms |
54748 KB |
Output is correct |
40 |
Correct |
146 ms |
54632 KB |
Output is correct |
41 |
Correct |
44 ms |
22544 KB |
Output is correct |
42 |
Correct |
73 ms |
35304 KB |
Output is correct |
43 |
Correct |
22 ms |
22268 KB |
Output is correct |
44 |
Correct |
129 ms |
49696 KB |
Output is correct |
45 |
Correct |
30 ms |
22348 KB |
Output is correct |
46 |
Correct |
46 ms |
22428 KB |
Output is correct |
47 |
Correct |
137 ms |
50004 KB |
Output is correct |
48 |
Correct |
123 ms |
50076 KB |
Output is correct |
49 |
Correct |
92 ms |
27328 KB |
Output is correct |
50 |
Correct |
82 ms |
27304 KB |
Output is correct |
51 |
Correct |
211 ms |
56520 KB |
Output is correct |
52 |
Correct |
181 ms |
56000 KB |
Output is correct |
53 |
Correct |
264 ms |
25732 KB |
Output is correct |
54 |
Correct |
130 ms |
39188 KB |
Output is correct |
55 |
Correct |
67 ms |
23396 KB |
Output is correct |
56 |
Correct |
180 ms |
51484 KB |
Output is correct |
57 |
Correct |
151 ms |
23980 KB |
Output is correct |
58 |
Correct |
211 ms |
24436 KB |
Output is correct |
59 |
Correct |
123 ms |
50148 KB |
Output is correct |