#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 10 , mod = 1e9 + 7;
long long n , x[N] , y[N] , mulx;
set <long long> st;
long long tav(long long a , long long b)
{
long long res = 1;
while(b)
{
if(b & 1)
res = 1LL * res * a % mod;
b >>= 1;
a = 1LL * a * a % mod;
}
return res;
}
struct SEG{
long long mx[N << 4];
void Build(long long node = 1 , long long nl = 0 , long long nr = n)
{
if(nr - nl == 1)
{
mx[node] = y[nl];
return;
}
long long mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
Build(lc , nl , mid); Build(rc , mid , nr);
mx[node] = max(mx[lc] , mx[rc]);
}
void Update(long long id , long long node = 1 , long long nl = 0 , long long nr = n)
{
if(nr - nl == 1)
{
mx[node] = y[nl];
return;
}
long long mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
if(id < mid)
Update(id , lc , nl , mid);
else
Update(id , rc , mid , nr);
mx[node] = max(mx[lc] , mx[rc]);
}
long long Get(long long l , long long r , long long node = 1 , long long nl = 0 , long long nr = n)
{
if(r <= nl || nr <= l)
return 0;
if(l <= nl && nr <= r)
return mx[node];
long long mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
return max(Get(l , r , lc , nl , mid) , Get(l , r , rc , mid , nr));
}
} seg;
long long Solve()
{
long long tmpx = 1 , mx_x = 1 , mx_y = 1;
//cout << "WPW " << endl;
for(auto asd : st)
{
auto u = abs(asd);
long long Y = seg.Get(u , n);
if(Y > 1LL * mx_x * mx_y)
{
mx_y = Y;
mx_x = x[u];
}
else
{
mx_x *= x[u];
}
tmpx *= x[u];
if(mx_x * mx_y > mod)
break;
}
//cout << " WER WE R" << endl;
long long res = mx_x * mx_y % mod;
if(seg.Get(0 , n) > mx_x * mx_y)
res = seg.Get(0 , n);
return 1LL * mulx * tav(tmpx % mod , mod - 2) % mod * res % mod;
}
int init(int nn, int X[], int Y[]) {
mulx = 1;
n = nn;
for(long long i = 0 ; i < n ; i++)
{
x[i] = X[i];
y[i] = Y[i];
mulx = 1LL * mulx * x[i] % mod;
}
seg.Build();
for(long long i = 0 ; i < n ; i++) if(x[i] > 1)
st.insert(-i);
return Solve();
}
int updateX(int pos, int val) {
if(x[pos] > 1)
st.erase(-pos);
mulx = 1LL * mulx * tav(x[pos] , mod - 2) % mod;
x[pos] = val;
if(x[pos] > 1)
st.insert(-pos);
mulx = 1LL * mulx * x[pos] % mod;
return Solve();
}
int updateY(int pos, int val) {
y[pos] = val;
seg.Update(pos);
return Solve();
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:102:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
102 | return Solve();
| ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:113:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
113 | return Solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:119:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
119 | return Solve();
| ~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
0 ms |
4444 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4532 KB |
Output is correct |
3 |
Correct |
0 ms |
4532 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4524 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4440 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4444 KB |
Output is correct |
22 |
Correct |
0 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
3 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
263 ms |
45812 KB |
Output is correct |
2 |
Correct |
216 ms |
45772 KB |
Output is correct |
3 |
Correct |
199 ms |
45904 KB |
Output is correct |
4 |
Correct |
209 ms |
45780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4440 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4444 KB |
Output is correct |
33 |
Correct |
25 ms |
21528 KB |
Output is correct |
34 |
Correct |
25 ms |
21588 KB |
Output is correct |
35 |
Correct |
137 ms |
44848 KB |
Output is correct |
36 |
Correct |
136 ms |
44884 KB |
Output is correct |
37 |
Correct |
31 ms |
21588 KB |
Output is correct |
38 |
Correct |
65 ms |
33392 KB |
Output is correct |
39 |
Correct |
17 ms |
21336 KB |
Output is correct |
40 |
Correct |
139 ms |
48208 KB |
Output is correct |
41 |
Correct |
26 ms |
22868 KB |
Output is correct |
42 |
Correct |
31 ms |
22608 KB |
Output is correct |
43 |
Correct |
120 ms |
48184 KB |
Output is correct |
44 |
Correct |
117 ms |
48092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
0 ms |
4444 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4444 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
0 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4440 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
260 ms |
45800 KB |
Output is correct |
34 |
Correct |
213 ms |
45904 KB |
Output is correct |
35 |
Correct |
197 ms |
45856 KB |
Output is correct |
36 |
Correct |
244 ms |
45904 KB |
Output is correct |
37 |
Correct |
29 ms |
21596 KB |
Output is correct |
38 |
Correct |
25 ms |
21596 KB |
Output is correct |
39 |
Correct |
136 ms |
44888 KB |
Output is correct |
40 |
Correct |
132 ms |
44884 KB |
Output is correct |
41 |
Correct |
31 ms |
21596 KB |
Output is correct |
42 |
Correct |
65 ms |
33312 KB |
Output is correct |
43 |
Correct |
18 ms |
21340 KB |
Output is correct |
44 |
Correct |
121 ms |
48296 KB |
Output is correct |
45 |
Correct |
26 ms |
22804 KB |
Output is correct |
46 |
Correct |
32 ms |
22800 KB |
Output is correct |
47 |
Correct |
120 ms |
48208 KB |
Output is correct |
48 |
Correct |
117 ms |
48216 KB |
Output is correct |
49 |
Correct |
92 ms |
26192 KB |
Output is correct |
50 |
Correct |
71 ms |
26188 KB |
Output is correct |
51 |
Correct |
232 ms |
52028 KB |
Output is correct |
52 |
Correct |
176 ms |
51928 KB |
Output is correct |
53 |
Correct |
196 ms |
25548 KB |
Output is correct |
54 |
Correct |
132 ms |
38628 KB |
Output is correct |
55 |
Correct |
62 ms |
23372 KB |
Output is correct |
56 |
Correct |
172 ms |
49496 KB |
Output is correct |
57 |
Correct |
148 ms |
23888 KB |
Output is correct |
58 |
Correct |
189 ms |
24248 KB |
Output is correct |
59 |
Correct |
117 ms |
48232 KB |
Output is correct |