#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<long long> x, y;
struct SegTree {
int size = 1;
vector<long long> pr;
vector<int> mx;
void init(){
while(size < (int)x.size())
size <<= 1;
pr.resize(size << 1, 1);
mx.resize(size << 1, 0);
build(0, 0, size);
}
void build(int ind, int lx, int rx){
if(lx + 1 == rx){
if(lx < x.size())
pr[ind] = x[lx], mx[ind] = y[lx];
return;
}
int mid = (lx + rx) >> 1;
build((ind << 1) + 1, lx, mid);
build((ind << 1) + 2, mid, rx);
pr[ind] = (pr[(ind << 1) + 1] * pr[(ind << 1) + 2]) % mod;
mx[ind] = max(mx[(ind << 1) + 1], mx[(ind << 1) + 2]);
}
void change(int pos, int val, int x, int lx, int rx){
if(lx + 1 == rx){
pr[x] = val;
return;
}
int mid = (lx + rx) >> 1;
if(pos < mid)
change(pos, val, (x << 1) + 1, lx, mid);
else
change(pos, val, (x << 1) + 2, mid, rx);
pr[x] = (pr[(x << 1) + 1] * pr[(x << 1) + 2]) % mod;
}
void change(int pos, int val){
change(pos, val, 0, 0, size);
}
void set(int pos, int val, int x, int lx, int rx){
if(lx + 1 == rx){
mx[x] = val;
return;
}
int mid = (lx + rx) >> 1;
if(pos < mid)
set(pos, val, (x << 1) + 1, lx, mid);
else
set(pos, val, (x << 1) + 2, mid, rx);
mx[x] = max(mx[(x << 1) + 1], mx[(x << 1) + 2]);
}
void set(int pos, int val){
set(pos, val, 0, 0, size);
}
long long get(int l, int r, int ind, int lx, int rx){
if(l <= lx and rx <= r)
return pr[ind];
if(r <= lx or rx <= l)
return 1;
int mid = (lx + rx) >> 1;
return (get(l, r, (ind << 1) + 1, lx, mid) * get(l, r, (ind << 1) + 2, mid, rx)) % mod;
}
long long get(int l, int r){
return get(l, r, 0, 0, size);
}
int res(int l, int r, int x, int lx, int rx){
if(l <= lx and rx <= r)
return mx[x];
if(r <= lx or rx <= l)
return 0;
int mid = (lx + rx) >> 1;
return max(res(l, r, (x << 1) + 1, lx, mid), res(l, r, (x << 1) + 2, mid, rx));
}
int res(int l, int r){
return res(l, r, 0, 0, size);
}
};
SegTree s;
set<int> st;
int init(int n, int X[], int Y[]) {
x.resize(n);
y.resize(n);
for(int i = 0; i < n; i ++)
x[i] = X[i], y[i] = Y[i];
st.insert(-1);
for(int i = 0; i < n; i ++)
if(x[i] != 1)
st.insert(i);
s.init();
auto cur = --st.end(), prev = cur;
long long y1 = s.res(max(0, *cur), n), p = 1, ans = (s.res(max(0, *cur), n) * s.get(0, *cur + 1)) % mod;
while(1){
if(prev == st.begin())
return ans;
prev --;
p = p * x[*cur];
if(p > (int)1e9 or y1 * p > (int)1e9)
return ans;
if(s.res(max(0, *prev), *cur + 1) > y1 * p){
y1 = s.res(max(0, *prev), *cur + 1);
p = 1;
ans = (y1 * s.get(0, *prev + 1)) % mod;
}
cur --;
}
return ans;
}
int updateX(int pos, int val) {
if(x[pos] != 1)
st.erase(pos);
x[pos] = val;
if(x[pos] != 1)
st.insert(pos);
s.change(pos, val);
int n = (int)x.size();
auto cur = --st.end(), prev = cur;
long long y1 = s.res(max(0, *cur), n), p = 1, ans = (s.res(max(0, *cur), n) * s.get(0, *cur + 1)) % mod;
while(1){
if(prev == st.begin())
return ans;
prev --;
p = p * x[*cur];
if(p > (int)1e9 or y1 * p > (int)1e9)
return ans;
if(s.res(max(0, *prev), *cur + 1) > y1 * p){
y1 = s.res(max(0, *prev), *cur + 1);
p = 1;
ans = (y1 * s.get(0, *prev + 1)) % mod;
}
cur --;
}
return ans;
}
int updateY(int pos, int val) {
y[pos] = val;
s.set(pos, val);
int n = (int)x.size();
auto cur = --st.end(), prev = cur;
long long y1 = s.res(max(0, *cur), n), p = 1, ans = (s.res(max(0, *cur), n) * s.get(0, *cur + 1)) % mod;
while(1){
if(prev == st.begin())
return ans;
prev --;
p = p * x[*cur];
if(p > (int)1e9 or y1 * p > (int)1e9)
return ans;
if(s.res(max(0, *prev), *cur + 1) > y1 * p){
y1 = s.res(max(0, *prev), *cur + 1);
p = 1;
ans = (y1 * s.get(0, *prev + 1)) % mod;
}
cur --;
}
return ans;
}
Compilation message
horses.cpp: In member function 'void SegTree::build(int, int, int)':
horses.cpp:24:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | if(lx < x.size())
| ~~~^~~~~~~~~~
horses.cpp:25:36: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
25 | pr[ind] = x[lx], mx[ind] = y[lx];
| ^
horses.cpp: In member function 'void SegTree::change(int, int, int, int, int)':
horses.cpp:35:36: warning: declaration of 'x' shadows a global declaration [-Wshadow]
35 | void change(int pos, int val, int x, int lx, int rx){
| ~~~~^
horses.cpp:6:19: note: shadowed declaration is here
6 | vector<long long> x, y;
| ^
horses.cpp: In member function 'void SegTree::set(int, int, int, int, int)':
horses.cpp:52:33: warning: declaration of 'x' shadows a global declaration [-Wshadow]
52 | void set(int pos, int val, int x, int lx, int rx){
| ~~~~^
horses.cpp:6:19: note: shadowed declaration is here
6 | vector<long long> x, y;
| ^
horses.cpp: In member function 'int SegTree::res(int, int, int, int, int)':
horses.cpp:82:28: warning: declaration of 'x' shadows a global declaration [-Wshadow]
82 | int res(int l, int r, int x, int lx, int rx){
| ~~~~^
horses.cpp:6:19: note: shadowed declaration is here
6 | vector<long long> x, y;
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:113:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
113 | return ans;
| ^~~
horses.cpp:117:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
117 | return ans;
| ^~~
horses.cpp:125:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
125 | return ans;
| ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:140:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
140 | return ans;
| ^~~
horses.cpp:144:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
144 | return ans;
| ^~~
horses.cpp:152:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
152 | return ans;
| ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:163:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
163 | return ans;
| ^~~
horses.cpp:167:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
167 | return ans;
| ^~~
horses.cpp:175:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
175 | return ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 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 |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
1 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 |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 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 |
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 |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
358 ms |
48800 KB |
Output is correct |
2 |
Correct |
244 ms |
48724 KB |
Output is correct |
3 |
Correct |
240 ms |
48860 KB |
Output is correct |
4 |
Correct |
252 ms |
48728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
412 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 |
1 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 |
1 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 |
344 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 |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 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 |
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 |
31 ms |
24668 KB |
Output is correct |
34 |
Correct |
34 ms |
24660 KB |
Output is correct |
35 |
Correct |
157 ms |
47952 KB |
Output is correct |
36 |
Correct |
139 ms |
47956 KB |
Output is correct |
37 |
Correct |
50 ms |
24660 KB |
Output is correct |
38 |
Correct |
72 ms |
36472 KB |
Output is correct |
39 |
Correct |
23 ms |
24408 KB |
Output is correct |
40 |
Correct |
137 ms |
48212 KB |
Output is correct |
41 |
Correct |
35 ms |
26452 KB |
Output is correct |
42 |
Correct |
43 ms |
26716 KB |
Output is correct |
43 |
Correct |
129 ms |
54356 KB |
Output is correct |
44 |
Correct |
124 ms |
54148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
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 |
348 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 |
1 ms |
344 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 |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 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 |
484 KB |
Output is correct |
33 |
Correct |
349 ms |
48776 KB |
Output is correct |
34 |
Correct |
228 ms |
48724 KB |
Output is correct |
35 |
Correct |
231 ms |
48724 KB |
Output is correct |
36 |
Correct |
247 ms |
48976 KB |
Output is correct |
37 |
Correct |
36 ms |
24656 KB |
Output is correct |
38 |
Correct |
28 ms |
24660 KB |
Output is correct |
39 |
Correct |
147 ms |
47956 KB |
Output is correct |
40 |
Correct |
139 ms |
47952 KB |
Output is correct |
41 |
Correct |
50 ms |
24664 KB |
Output is correct |
42 |
Correct |
74 ms |
36436 KB |
Output is correct |
43 |
Correct |
23 ms |
24412 KB |
Output is correct |
44 |
Correct |
130 ms |
47956 KB |
Output is correct |
45 |
Correct |
36 ms |
26456 KB |
Output is correct |
46 |
Correct |
42 ms |
26448 KB |
Output is correct |
47 |
Correct |
127 ms |
54120 KB |
Output is correct |
48 |
Correct |
127 ms |
54352 KB |
Output is correct |
49 |
Correct |
97 ms |
31608 KB |
Output is correct |
50 |
Correct |
82 ms |
31484 KB |
Output is correct |
51 |
Correct |
253 ms |
60668 KB |
Output is correct |
52 |
Correct |
191 ms |
60268 KB |
Output is correct |
53 |
Correct |
319 ms |
29780 KB |
Output is correct |
54 |
Correct |
164 ms |
43348 KB |
Output is correct |
55 |
Correct |
95 ms |
27580 KB |
Output is correct |
56 |
Correct |
205 ms |
55636 KB |
Output is correct |
57 |
Correct |
200 ms |
28276 KB |
Output is correct |
58 |
Correct |
279 ms |
28756 KB |
Output is correct |
59 |
Correct |
129 ms |
54356 KB |
Output is correct |