#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();
| ~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 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 |
1 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 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 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 |
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 |
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 |
388 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
281 ms |
44716 KB |
Output is correct |
2 |
Correct |
253 ms |
44692 KB |
Output is correct |
3 |
Correct |
233 ms |
44700 KB |
Output is correct |
4 |
Correct |
244 ms |
44668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
264 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 |
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 |
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 |
29 ms |
20408 KB |
Output is correct |
34 |
Correct |
29 ms |
20404 KB |
Output is correct |
35 |
Correct |
143 ms |
43832 KB |
Output is correct |
36 |
Correct |
138 ms |
43844 KB |
Output is correct |
37 |
Correct |
42 ms |
20420 KB |
Output is correct |
38 |
Correct |
73 ms |
32460 KB |
Output is correct |
39 |
Correct |
22 ms |
20180 KB |
Output is correct |
40 |
Correct |
127 ms |
43736 KB |
Output is correct |
41 |
Correct |
30 ms |
20332 KB |
Output is correct |
42 |
Correct |
36 ms |
20348 KB |
Output is correct |
43 |
Correct |
122 ms |
43728 KB |
Output is correct |
44 |
Correct |
122 ms |
43752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
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 |
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 |
280 ms |
44648 KB |
Output is correct |
34 |
Correct |
235 ms |
44720 KB |
Output is correct |
35 |
Correct |
228 ms |
44640 KB |
Output is correct |
36 |
Correct |
242 ms |
44620 KB |
Output is correct |
37 |
Correct |
29 ms |
20392 KB |
Output is correct |
38 |
Correct |
28 ms |
20460 KB |
Output is correct |
39 |
Correct |
146 ms |
43820 KB |
Output is correct |
40 |
Correct |
139 ms |
43820 KB |
Output is correct |
41 |
Correct |
43 ms |
20460 KB |
Output is correct |
42 |
Correct |
71 ms |
32228 KB |
Output is correct |
43 |
Correct |
22 ms |
20284 KB |
Output is correct |
44 |
Correct |
125 ms |
43736 KB |
Output is correct |
45 |
Correct |
30 ms |
20328 KB |
Output is correct |
46 |
Correct |
38 ms |
20300 KB |
Output is correct |
47 |
Correct |
122 ms |
43688 KB |
Output is correct |
48 |
Correct |
121 ms |
43724 KB |
Output is correct |
49 |
Correct |
82 ms |
22308 KB |
Output is correct |
50 |
Correct |
76 ms |
22344 KB |
Output is correct |
51 |
Correct |
213 ms |
44772 KB |
Output is correct |
52 |
Correct |
176 ms |
44740 KB |
Output is correct |
53 |
Correct |
251 ms |
22248 KB |
Output is correct |
54 |
Correct |
130 ms |
35212 KB |
Output is correct |
55 |
Correct |
68 ms |
20428 KB |
Output is correct |
56 |
Correct |
182 ms |
44668 KB |
Output is correct |
57 |
Correct |
144 ms |
21176 KB |
Output is correct |
58 |
Correct |
208 ms |
21344 KB |
Output is correct |
59 |
Correct |
123 ms |
43656 KB |
Output is correct |