#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll md = 1e9+7;
const ll L = 1e9+5;
struct segtree_for_product{
int k = 1;
vector<ll> P;
segtree_for_product(int n){
while(k < n) k<<=1;
P.assign(2*k, 1);
}
void update(int i, ll x){
i+=k;
P[i] = x%md;
i>>=1;
while(i){
P[i] = (P[i<<1]*P[(i<<1)+1])%md;
i>>=1;
}
}
ll product(int l, int r, int nd, int a, int b){
if(a > r || b < l) return 1;
if(a >= l && b <= r) return P[nd];
int mid = (a+b)>>1;
return (product(l, r, nd<<1, a, mid)*product(l, r, (nd<<1)+1, mid+1, b))%md;
}
ll product(int l, int r){
return product(l, r, 1, 0, k-1);
}
};
struct segtree_for_maximum{
int k = 1;
vector<ll> P;
segtree_for_maximum(int n){
while(k < n) k<<=1;
P.assign(2*k, 0);
}
void update(int i, ll x){
i+=k;
P[i] = x;
i>>=1;
while(i){
P[i] = max(P[i<<1], P[(i<<1)+1]);
i>>=1;
}
}
ll getmax(int l, int r, int nd, int a, int b){
if(a > r || b < l) return 0;
if(a >= l && b <= r) return P[nd];
int mid = (a+b)>>1;
return max(getmax(l, r, nd<<1, a, mid), getmax(l, r, (nd<<1)+1, mid+1, b));
}
ll getmax(int l, int r){
return getmax(l, r, 1, 0, k-1);
}
};
int n;
vector<int> X, Y;
segtree_for_product segx(0);
segtree_for_maximum segy(0);
set<int> candidates;
int query(){
int fi = 0;
ll p = 1;
for(auto it = candidates.rbegin(); it != candidates.rend(); it++){
p*=X[*it];
if(p > L){
fi = *it;
break;
}
}
ll ans = 0;
p = 1;
int j = fi;
while(j < n){
if(j != fi) p*=X[j];
auto it = candidates.upper_bound(j);
int nxt = n;
if(it != candidates.end()) nxt = *it;
ans = max(ans, p*segy.getmax(j, nxt-1));
j = nxt;
}
ans%=md;
ans*=segx.product(0, fi), ans%=md;
return ans;
}
int init(int _n, int _X[], int _Y[]){
swap(n, _n);
X.resize(n), Y.resize(n);
segx = segtree_for_product(n);
segy = segtree_for_maximum(n);
for(int i = 0; i < n; i++){
X[i] = _X[i], Y[i] = _Y[i], segx.update(i, X[i]), segy.update(i, Y[i]);
if(X[i] > 1) candidates.insert(i);
}
return query();
}
int updateX(int i, int x){
if(X[i] > 1) candidates.erase(i);
X[i] = x;
if(X[i] > 1) candidates.insert(i);
segx.update(i, x);
return query();
}
int updateY(int i, int y){
Y[i] = y;
segy.update(i, y);
return query();
}
Compilation message
horses.cpp: In function 'int query()':
horses.cpp:97:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
97 | return ans;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 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 |
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 |
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 |
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 |
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 |
3 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 |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
720 ms |
49048 KB |
Output is correct |
2 |
Correct |
389 ms |
49100 KB |
Output is correct |
3 |
Correct |
350 ms |
49024 KB |
Output is correct |
4 |
Correct |
421 ms |
49004 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 |
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 |
240 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 |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
121 ms |
24680 KB |
Output is correct |
34 |
Correct |
112 ms |
24684 KB |
Output is correct |
35 |
Correct |
235 ms |
48140 KB |
Output is correct |
36 |
Correct |
218 ms |
48116 KB |
Output is correct |
37 |
Correct |
142 ms |
24684 KB |
Output is correct |
38 |
Correct |
163 ms |
36576 KB |
Output is correct |
39 |
Correct |
105 ms |
24548 KB |
Output is correct |
40 |
Correct |
224 ms |
53968 KB |
Output is correct |
41 |
Correct |
122 ms |
26604 KB |
Output is correct |
42 |
Correct |
129 ms |
26636 KB |
Output is correct |
43 |
Correct |
207 ms |
54332 KB |
Output is correct |
44 |
Correct |
202 ms |
54360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
292 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 |
1 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 |
224 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 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 |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
731 ms |
49004 KB |
Output is correct |
34 |
Correct |
351 ms |
48988 KB |
Output is correct |
35 |
Correct |
353 ms |
48948 KB |
Output is correct |
36 |
Correct |
404 ms |
49020 KB |
Output is correct |
37 |
Correct |
112 ms |
24652 KB |
Output is correct |
38 |
Correct |
110 ms |
24676 KB |
Output is correct |
39 |
Correct |
250 ms |
48108 KB |
Output is correct |
40 |
Correct |
233 ms |
48044 KB |
Output is correct |
41 |
Correct |
140 ms |
24680 KB |
Output is correct |
42 |
Correct |
160 ms |
36612 KB |
Output is correct |
43 |
Correct |
103 ms |
24564 KB |
Output is correct |
44 |
Correct |
215 ms |
54048 KB |
Output is correct |
45 |
Correct |
126 ms |
26600 KB |
Output is correct |
46 |
Correct |
121 ms |
26692 KB |
Output is correct |
47 |
Correct |
198 ms |
54380 KB |
Output is correct |
48 |
Correct |
242 ms |
54360 KB |
Output is correct |
49 |
Correct |
181 ms |
31624 KB |
Output is correct |
50 |
Correct |
171 ms |
31700 KB |
Output is correct |
51 |
Correct |
398 ms |
60780 KB |
Output is correct |
52 |
Correct |
307 ms |
60376 KB |
Output is correct |
53 |
Correct |
474 ms |
29972 KB |
Output is correct |
54 |
Correct |
338 ms |
43444 KB |
Output is correct |
55 |
Correct |
168 ms |
27696 KB |
Output is correct |
56 |
Correct |
275 ms |
55828 KB |
Output is correct |
57 |
Correct |
289 ms |
28260 KB |
Output is correct |
58 |
Correct |
346 ms |
28740 KB |
Output is correct |
59 |
Correct |
237 ms |
54300 KB |
Output is correct |