#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cout << H << " ";
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 5e5 + 10;
const int mod = 1e9 + 7;
int n;
ll x[maxn], y[maxn];
ll seg[maxn << 2], dp[maxn << 2][2];
bool of[maxn << 2];
void build(int v, int l, int r){
if (l + 1 == r){
seg[v] = x[l];
return;
}
int mid = (l + r) >> 1;
build(v << 1, l, mid);
build(v << 1 | 1, mid, r);
ll tmp = 1ll * seg[v << 1] * seg[v << 1 | 1];
if (tmp >= mod || of[v << 1] || of[v << 1 | 1]) of[v] = true;
seg[v] = tmp % mod;
}
void change(int v, int l, int r, int idx){
if (idx < l || r <= idx) return;
if (l + 1 == r){
seg[v] = x[l];
return;
}
int mid = (l + r) >> 1;
change(v << 1, l, mid, idx);
change(v << 1 | 1, mid, r, idx);
ll tmp = 1ll * seg[v << 1] * seg[v << 1 | 1];
if (tmp >= mod || of[v << 1] || of[v << 1 | 1]) of[v] = true;
seg[v] = tmp % mod;
}
int find(int v, int l, int r, int tmp){
if (!of[v] && 1ll * tmp * seg[v] < mod) return -1;
if (l + 1 == r) return l;
int mid = (l + r) >> 1;
int res = find(v << 1 | 1, mid, r, tmp);
if (res == -1){
tmp *= seg[v << 1 | 1];
res = find(v << 1, l, mid, tmp);
}
return res;
}
int get(int v, int l, int r, int ql, int qr){
if (qr <= l || r <= ql) return 1;
if (ql <= l && r <= qr) return seg[v];
int mid = (l + r) >> 1;
return 1ll * get(v << 1, l, mid, ql, qr) * get(v << 1 | 1, mid, r, ql, qr) % mod;
}
void build2(int v, int l, int r){
if (l + 1 == r){
dp[v][0] = x[l] * y[l];
dp[v][1] = x[l];
return;
}
int mid = (l + r) >> 1;
build2(v << 1, l, mid);
build2(v << 1 | 1, mid, r);
dp[v][0] = max(dp[v << 1][0], dp[v << 1][1] * dp[v << 1 | 1][0]);
dp[v][1] = dp[v << 1][1] * dp[v << 1 | 1][1];
}
void change2(int v, int l, int r, int idx){
if (idx < l || r <= idx) return;
if (l + 1 == r){
dp[v][0] = x[l] * y[l];
dp[v][1] = x[l];
return;
}
int mid = (l + r) >> 1;
change2(v << 1, l, mid, idx);
change2(v << 1 | 1, mid, r, idx);
dp[v][0] = max(dp[v << 1][0], dp[v << 1][1] * dp[v << 1 | 1][0]);
dp[v][1] = dp[v << 1][1] * dp[v << 1 | 1][1];
}
pll get2(int v, int l, int r, int ql, int qr){
if (qr <= l || r <= ql) return {1, 1};
if (ql <= l && r <= qr) return MP(dp[v][0], dp[v][1]);
int mid = (l + r) >> 1;
pll a = get2(v << 1, l, mid, ql, qr);
pll b = get2(v << 1 | 1, mid, r, ql, qr);
return MP(max(a.F, a.S * b.F), a.S * b.S);
}
set<int> st;
int Calc(){
int idx = find(1, 0, n, 1);
if (idx == -1) idx = 0;
int tmp = get(1, 0, n, 0, idx+1);
ll tmp2 = max(y[idx], get2(1, 0, n+1, idx+1, n+1).F) % mod;
return 1ll * tmp * tmp2 % mod;
}
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];
if (x[i] > 1) st.insert(i);
}
build(1, 0, n);
build2(1, 0, n+1);
return Calc();
}
int updateX(int pos, int val) {
st.erase(pos);
x[pos] = val;
if (val > 1) st.insert(pos);
change(1, 0, n, pos);
change2(1, 0, n+1, pos);
return Calc();
}
int updateY(int pos, int val) {
y[pos] = val;
change2(1, 0, n+1, pos);
return Calc();
}
Compilation message
horses.cpp: In function 'int find(int, int, int, int)':
horses.cpp:68:7: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
68 | tmp *= seg[v << 1 | 1];
| ~~~~^~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int get(int, int, int, int, int)':
horses.cpp:76:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
76 | if (ql <= l && r <= qr) return seg[v];
| ~~~~~^
horses.cpp:78:77: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
78 | return 1ll * get(v << 1, l, mid, ql, qr) * get(v << 1 | 1, mid, r, ql, qr) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int Calc()':
horses.cpp:124:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
124 | return 1ll * tmp * tmp2 % mod;
| ~~~~~~~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 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 |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
191 ms |
61200 KB |
Output is correct |
2 |
Correct |
348 ms |
61560 KB |
Output is correct |
3 |
Correct |
314 ms |
61612 KB |
Output is correct |
4 |
Correct |
402 ms |
61556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 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 |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
50 ms |
36980 KB |
Output is correct |
34 |
Correct |
52 ms |
36900 KB |
Output is correct |
35 |
Correct |
161 ms |
60748 KB |
Output is correct |
36 |
Correct |
168 ms |
60676 KB |
Output is correct |
37 |
Correct |
51 ms |
36808 KB |
Output is correct |
38 |
Correct |
90 ms |
48684 KB |
Output is correct |
39 |
Correct |
39 ms |
36784 KB |
Output is correct |
40 |
Correct |
273 ms |
60684 KB |
Output is correct |
41 |
Correct |
44 ms |
36784 KB |
Output is correct |
42 |
Correct |
38 ms |
36760 KB |
Output is correct |
43 |
Correct |
137 ms |
60616 KB |
Output is correct |
44 |
Correct |
139 ms |
60700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 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 |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
190 ms |
61188 KB |
Output is correct |
34 |
Correct |
359 ms |
61660 KB |
Output is correct |
35 |
Correct |
301 ms |
61620 KB |
Output is correct |
36 |
Correct |
394 ms |
61644 KB |
Output is correct |
37 |
Correct |
59 ms |
36992 KB |
Output is correct |
38 |
Correct |
58 ms |
36964 KB |
Output is correct |
39 |
Correct |
162 ms |
60748 KB |
Output is correct |
40 |
Correct |
160 ms |
60672 KB |
Output is correct |
41 |
Correct |
47 ms |
36876 KB |
Output is correct |
42 |
Correct |
89 ms |
48720 KB |
Output is correct |
43 |
Correct |
39 ms |
36664 KB |
Output is correct |
44 |
Correct |
306 ms |
60680 KB |
Output is correct |
45 |
Correct |
35 ms |
36788 KB |
Output is correct |
46 |
Correct |
38 ms |
36784 KB |
Output is correct |
47 |
Correct |
138 ms |
60660 KB |
Output is correct |
48 |
Correct |
137 ms |
60676 KB |
Output is correct |
49 |
Correct |
175 ms |
39260 KB |
Output is correct |
50 |
Correct |
172 ms |
39152 KB |
Output is correct |
51 |
Correct |
242 ms |
61624 KB |
Output is correct |
52 |
Correct |
229 ms |
61572 KB |
Output is correct |
53 |
Correct |
155 ms |
38740 KB |
Output is correct |
54 |
Correct |
192 ms |
51740 KB |
Output is correct |
55 |
Correct |
105 ms |
36812 KB |
Output is correct |
56 |
Execution timed out |
1582 ms |
61092 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |