// #include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007;
#define pb push_back
int n, x[500005], y[500005];
set<int, greater<int>> s;
struct node
{
long long val;
node *l, *r;
} *root1, *root2;
node* build1(int l,int r)
{
node *ptr = new node;
if(l == r)
{
ptr->val = x[l];
return ptr;
}
int mid = (l + r) / 2;
ptr->l = build1(l, mid);
ptr->r = build1(mid + 1, r);
ptr->val = ptr->l->val * ptr->r->val;
ptr->val %= mod;
return ptr;
}
node* build2(int l,int r)
{
node *ptr = new node;
if(l == r)
{
ptr->val = y[l];
return ptr;
}
int mid = (l + r) / 2;
ptr->l = build2(l, mid);
ptr->r = build2(mid + 1, r);
ptr->val = max(ptr->l->val, ptr->r->val);
return ptr;
}
int ll,rr;
long long que1(node *ptr, int l,int r)
{
if(ll <= l && r <= rr) return ptr->val;
if(r < ll || rr < l) return 1;
int mid = (l + r) / 2;
return (que1(ptr->l, l, mid) * que1(ptr->r, mid + 1, r)) % mod;
}
int que2(node *ptr, int l,int r)
{
if(ll <= l && r <= rr) return ptr->val;
if(r < ll || rr < l) return 0;
int mid = (l + r) / 2;
return max(que2(ptr->l, l, mid),que2(ptr->r, mid + 1, r));
}
int up_po,up_val;
void up1(node *ptr, int l,int r)
{
if(l == r)
{
ptr->val = up_val;
return ;
}
int mid = (l + r) / 2;
if(up_po <= mid) up1(ptr->l, l, mid);
else up1(ptr->r, mid + 1, r);
ptr->val = ptr->l->val * ptr->r->val;
ptr->val %= mod;
}
void up2(node *ptr, int l,int r)
{
if(l == r)
{
ptr->val = up_val;
return ;
}
int mid = (l + r) / 2;
if(up_po <= mid) up2(ptr->l, l, mid);
else up2(ptr->r, mid + 1, r);
ptr->val = max(ptr->l->val, ptr->r->val);
}
int cal()
{
vector<int> idx = { n };
long long val = 1;
for(int sidx : s)
{
idx.pb(sidx);
val *= x[sidx];
if (val > 1e9 + 5)
break;
}
if(val <= 1e9 + 5 && idx.back() != 0)
idx.pb(0);
reverse(idx.begin(), idx.end());
long long mx = 0, xval = 1ll;
int best = 0, ybest = 0;
for(int i = 0; i < idx.size() - 1; i++)
{
if(i != 0)
xval *= x[idx[i]];
ll = idx[i];
rr = idx[i + 1] - 1;
int ymax = que2(root2, 0, n - 1);
ll = idx[1];
rr = idx[i];
// long long xval = que1(root1, 0, n - 1);
// printf("%lld\n",xval);
if (ymax * xval > mx)
mx = ymax * xval, best = i, ybest = ymax;
}
ll = 0;
rr = idx[best];
return ((que1(root1, 0, n - 1) * ybest) ) % 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];
root1 = build1(0, n - 1);
root2 = build2(0, n - 1);
for(int i = 0; i < n; i++)
if(x[i] != 1)
s.insert(i);
return cal();
}
int updateX(int pos, int val)
{
x[pos] = val;
up_po = pos;
up_val = val;
up1(root1, 0, n - 1);
if (val == 1) s.erase(pos);
else s.insert(pos);
return cal();
}
int updateY(int pos, int val)
{
y[pos] = val;
up_po = pos;
up_val = val;
up2(root2, 0, n - 1);
return cal();
}
Compilation message
horses.cpp: In function 'int que2(node*, int, int)':
horses.cpp:59:40: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
59 | if(ll <= l && r <= rr) return ptr->val;
| ~~~~~^~~
horses.cpp: In function 'int cal()':
horses.cpp:102:7: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
102 | if (val > 1e9 + 5)
| ^~~
horses.cpp:106:5: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
106 | if(val <= 1e9 + 5 && idx.back() != 0)
| ^~~
horses.cpp:112:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for(int i = 0; i < idx.size() - 1; i++)
| ~~^~~~~~~~~~~~~~~~
horses.cpp:129:44: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
129 | return ((que1(root1, 0, n - 1) * ybest) ) % mod;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
456 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
4 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
448 KB |
Output is correct |
32 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
672 ms |
95828 KB |
Output is correct |
2 |
Correct |
433 ms |
95868 KB |
Output is correct |
3 |
Correct |
420 ms |
98040 KB |
Output is correct |
4 |
Correct |
475 ms |
98136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
308 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
316 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
4 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
444 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
5 ms |
468 KB |
Output is correct |
33 |
Correct |
102 ms |
73816 KB |
Output is correct |
34 |
Correct |
101 ms |
73748 KB |
Output is correct |
35 |
Correct |
264 ms |
97384 KB |
Output is correct |
36 |
Correct |
248 ms |
97332 KB |
Output is correct |
37 |
Correct |
160 ms |
72964 KB |
Output is correct |
38 |
Correct |
165 ms |
85632 KB |
Output is correct |
39 |
Correct |
88 ms |
72732 KB |
Output is correct |
40 |
Correct |
245 ms |
97360 KB |
Output is correct |
41 |
Correct |
122 ms |
72788 KB |
Output is correct |
42 |
Correct |
128 ms |
72920 KB |
Output is correct |
43 |
Correct |
229 ms |
97120 KB |
Output is correct |
44 |
Correct |
229 ms |
97100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
312 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 |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
480 KB |
Output is correct |
26 |
Correct |
1 ms |
472 KB |
Output is correct |
27 |
Correct |
4 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
448 KB |
Output is correct |
30 |
Correct |
2 ms |
448 KB |
Output is correct |
31 |
Correct |
3 ms |
448 KB |
Output is correct |
32 |
Correct |
4 ms |
484 KB |
Output is correct |
33 |
Correct |
690 ms |
98020 KB |
Output is correct |
34 |
Correct |
408 ms |
98332 KB |
Output is correct |
35 |
Correct |
428 ms |
98120 KB |
Output is correct |
36 |
Correct |
483 ms |
98200 KB |
Output is correct |
37 |
Correct |
103 ms |
73796 KB |
Output is correct |
38 |
Correct |
100 ms |
73856 KB |
Output is correct |
39 |
Correct |
267 ms |
97404 KB |
Output is correct |
40 |
Correct |
242 ms |
97344 KB |
Output is correct |
41 |
Correct |
182 ms |
73056 KB |
Output is correct |
42 |
Correct |
164 ms |
85580 KB |
Output is correct |
43 |
Correct |
94 ms |
72764 KB |
Output is correct |
44 |
Correct |
247 ms |
97196 KB |
Output is correct |
45 |
Correct |
110 ms |
72884 KB |
Output is correct |
46 |
Correct |
128 ms |
72856 KB |
Output is correct |
47 |
Correct |
240 ms |
97168 KB |
Output is correct |
48 |
Correct |
230 ms |
97204 KB |
Output is correct |
49 |
Correct |
261 ms |
75696 KB |
Output is correct |
50 |
Correct |
273 ms |
75676 KB |
Output is correct |
51 |
Correct |
393 ms |
98200 KB |
Output is correct |
52 |
Correct |
346 ms |
98188 KB |
Output is correct |
53 |
Correct |
748 ms |
75576 KB |
Output is correct |
54 |
Correct |
338 ms |
89832 KB |
Output is correct |
55 |
Correct |
189 ms |
73816 KB |
Output is correct |
56 |
Correct |
400 ms |
99404 KB |
Output is correct |
57 |
Correct |
409 ms |
74444 KB |
Output is correct |
58 |
Correct |
591 ms |
75020 KB |
Output is correct |
59 |
Correct |
233 ms |
98472 KB |
Output is correct |