#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+5;
const int mod = 1e9+7;
int st_max[4*maxn], st_prod[4*maxn];
int mult[maxn], cost[maxn];
int n;
void build(int X[], int Y[], int l = 0, int r = n-1, int id = 1){
if(l == r){
st_max[id] = Y[l];
st_prod[id] = X[l];
}
else {
int mid = (l+r)>>1;
build(X, Y, l, mid, id<<1);
build(X, Y, mid+1, r, id<<1|1);
st_max[id] = max(st_max[id<<1], st_max[id<<1|1]);
st_prod[id] = 1LL*st_prod[id<<1]*st_prod[id<<1|1]%mod;
}
}
void edit_max(int pos, int val, int l = 0, int r = n-1, int id = 1){
if(l == r)st_max[id] = val;
else {
int mid = (l+r)>>1;
if(pos <= mid)edit_max(pos, val, l, mid, id<<1);
else edit_max(pos, val, mid+1, r, id<<1|1);
st_max[id] = max(st_max[id<<1], st_max[id<<1|1]);
}
}
int get_max(int ql, int qr, int l = 0, int r = n-1, int id = 1){
if(ql > r || l > qr)return 0;
if(ql <= l && r <= qr)return st_max[id];
int mid = (l+r)>>1;
return max(get_max(ql, qr, l, mid, id<<1), get_max(ql, qr, mid+1, r, id<<1|1));
}
void edit_prod(int pos, int val, int l = 0, int r = n - 1, int id = 1){
if(l == r)st_prod[id] = val;
else {
int mid = (l+r)>>1;
if(pos <= mid)edit_prod(pos, val, l, mid, id<<1);
else edit_prod(pos, val, mid+1, r, id<<1|1);
st_prod[id] = 1LL*st_prod[id<<1]*st_prod[id<<1|1]%mod;
}
}
int get_prod(int ql, int qr, int l = 0, int r = n-1, int id = 1){
if(ql > r || l > qr)return 1;
if(ql <= l && r <= qr)return st_prod[id];
int mid = (l+r)>>1;
return 1LL*get_prod(ql, qr, l, mid, id<<1)*get_prod(ql, qr, mid+1, r, id<<1|1)%mod;
}
set<int> st;
int solve(){
int best = 0, bcost = 0, prv = n;
long long mx = 0;
for(auto it = st.rbegin(); it != st.rend(); it++){
int nw = get_max(*it, prv - 1);
// cout << nw << " " << mx << endl;
if(nw > mx){
mx = nw;
best = *it;
bcost = nw;
}
mx*=mult[*it];
if(mx >= mod)break;
}
return 1LL*get_prod(0, best)*bcost%mod;
}
int init(int N, int X[], int Y[]) {
n = N;
build(X, Y);
for(int i = 0; i < N; i++){
mult[i] = X[i];
cost[i] = Y[i];
if(X[i] > 1)st.insert(i);
}
st.insert(0);
return solve();
}
int updateX(int pos, int val) {
if(mult[pos] > 1)st.erase(pos);
mult[pos] = val;
edit_prod(pos, val);
if(mult[pos] > 1)st.insert(pos);
st.insert(0);
return solve();
}
int updateY(int pos, int val) {
cost[pos] = val;
edit_max(pos, val);
return solve();
}
Compilation message
horses.cpp: In function 'void build(int*, int*, int, int, int)':
horses.cpp:24:52: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
24 | st_prod[id] = 1LL*st_prod[id<<1]*st_prod[id<<1|1]%mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void edit_prod(int, int, int, int, int)':
horses.cpp:51:52: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
51 | st_prod[id] = 1LL*st_prod[id<<1]*st_prod[id<<1|1]%mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int get_prod(int, int, int, int, int)':
horses.cpp:59:80: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
59 | return 1LL*get_prod(ql, qr, l, mid, id<<1)*get_prod(ql, qr, mid+1, r, id<<1|1)%mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int solve()':
horses.cpp:79:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
79 | return 1LL*get_prod(0, best)*bcost%mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
448 KB |
Output is correct |
12 |
Correct |
0 ms |
440 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
448 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
440 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
448 KB |
Output is correct |
19 |
Correct |
0 ms |
416 KB |
Output is correct |
20 |
Correct |
0 ms |
448 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
448 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
375 ms |
44632 KB |
Output is correct |
2 |
Correct |
268 ms |
53432 KB |
Output is correct |
3 |
Correct |
246 ms |
44736 KB |
Output is correct |
4 |
Correct |
260 ms |
48396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
452 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
36 ms |
20440 KB |
Output is correct |
34 |
Correct |
30 ms |
20460 KB |
Output is correct |
35 |
Correct |
157 ms |
50864 KB |
Output is correct |
36 |
Correct |
142 ms |
50820 KB |
Output is correct |
37 |
Correct |
48 ms |
18772 KB |
Output is correct |
38 |
Correct |
76 ms |
31476 KB |
Output is correct |
39 |
Correct |
24 ms |
18520 KB |
Output is correct |
40 |
Correct |
133 ms |
45904 KB |
Output is correct |
41 |
Correct |
38 ms |
18524 KB |
Output is correct |
42 |
Correct |
45 ms |
18596 KB |
Output is correct |
43 |
Correct |
120 ms |
46164 KB |
Output is correct |
44 |
Correct |
119 ms |
46128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
380 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
388 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
440 KB |
Output is correct |
23 |
Correct |
1 ms |
536 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
476 KB |
Output is correct |
26 |
Correct |
1 ms |
476 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
359 ms |
44628 KB |
Output is correct |
34 |
Correct |
227 ms |
53336 KB |
Output is correct |
35 |
Correct |
224 ms |
44496 KB |
Output is correct |
36 |
Correct |
241 ms |
48464 KB |
Output is correct |
37 |
Correct |
31 ms |
20516 KB |
Output is correct |
38 |
Correct |
31 ms |
20572 KB |
Output is correct |
39 |
Correct |
143 ms |
50888 KB |
Output is correct |
40 |
Correct |
158 ms |
51032 KB |
Output is correct |
41 |
Correct |
50 ms |
18768 KB |
Output is correct |
42 |
Correct |
73 ms |
31496 KB |
Output is correct |
43 |
Correct |
24 ms |
18524 KB |
Output is correct |
44 |
Correct |
127 ms |
45940 KB |
Output is correct |
45 |
Correct |
38 ms |
18476 KB |
Output is correct |
46 |
Correct |
47 ms |
18776 KB |
Output is correct |
47 |
Correct |
119 ms |
46184 KB |
Output is correct |
48 |
Correct |
120 ms |
46304 KB |
Output is correct |
49 |
Correct |
103 ms |
23464 KB |
Output is correct |
50 |
Correct |
77 ms |
23636 KB |
Output is correct |
51 |
Correct |
233 ms |
52564 KB |
Output is correct |
52 |
Correct |
167 ms |
52308 KB |
Output is correct |
53 |
Correct |
343 ms |
21756 KB |
Output is correct |
54 |
Correct |
180 ms |
35408 KB |
Output is correct |
55 |
Correct |
76 ms |
19572 KB |
Output is correct |
56 |
Correct |
202 ms |
47700 KB |
Output is correct |
57 |
Correct |
203 ms |
20140 KB |
Output is correct |
58 |
Correct |
286 ms |
20564 KB |
Output is correct |
59 |
Correct |
126 ms |
46160 KB |
Output is correct |