#include "horses.h"
#include <bits/stdc++.h>
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
struct SegmentTree{
vector<int> st;
void modify(int pos, int v, int L, int R, int id){
if(L == R){
st[id] = v;
return;
}
int M = (L + R) / 2;
if(pos <= M) modify(pos, v, L, M, 2 * id + 1);
else modify(pos, v, M + 1, R, 2 * id + 2);
st[id] = max(st[2 * id + 1], st[2 * id + 2]);
}
int query(int l, int r, int L, int R, int id){
if(l == L && r == R){
return st[id];
}
int M = (L + R) / 2;
if(r <= M) return query(l, r, L, M, 2 * id + 1);
else if(l > M) return query(l, r, M + 1, R, 2 * id + 2);
else return max(query(l, M, L, M, 2 * id + 1), query(M + 1, r, M + 1, R, 2 * id + 2));
}
};
struct BIT{
vector<ll> bit;
int lowbit(int x){
return x & -x;
}
void modify(int x, ll v){
x++;
for(; x < bit.size(); x += lowbit(x)){
bit[x] = bit[x] * v % MOD;
}
}
ll query(int x){
x++;
ll ans = 1;
for(; x > 0; x -= lowbit(x)){
ans = ans * bit[x] % MOD;
}
return ans;
}
};
ll inv(ll a){
ll b = MOD - 2;
ll ans = 1;
while(b > 0){
if(b & 1) ans = ans * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return ans;
}
SegmentTree st;
BIT bit;
int n;
vector<int> x, y;
set<int> large;
ll calc(){
//cerr << "test\n";
//printv(large, cerr);
int now = n;
ll ans = 0;
int cnt = 0;
while(ans <= 1000000000 && now >= 0){
//cerr << now << " " << ans << "\n";
ans = ans * x[now];
auto it = large.lower_bound(now);
int nxt;
if(it == large.begin()) nxt = 0;
else nxt = *prev(it) + 1;
//cerr << nxt << "\n";
ans = max(ans, (ll)st.query(nxt, now, 0, n, 0));
now = nxt - 1;
}
ans %= MOD;
//printv(x, cerr);
//printv(bit.bit, cerr);
if(now >= 0) ans = ans * bit.query(now) % MOD;
//cerr << "ok " << now << " " << ans << "\n";
return ans;
}
void qq(){
st.st.clear();
bit.bit.clear();
large.clear();
st.st.resize(4 * (n + 1));
bit.bit.resize(n + 1, 1);
x[n] = 1;
for(int i = 0; i < n; i++){
st.modify(i + 1, y[i + 1], 0, n, 0);
bit.modify(i, x[i]);
if(x[i] >= 2) large.insert(i);
}
}
int init(int N, int X[], int Y[]){
n = N;
x.resize(n + 1);
y.resize(n + 1);
for(int i = 0; i < n; i++){
x[i] = X[i];
y[i + 1] = Y[i];
}
qq();
ll ans = calc();
//printv(x, cerr);
//printv(y, cerr);
return ans;
}
int updateX(int pos, int val){
if(x[pos] >= 2) large.erase(pos);
bit.modify(pos, inv(x[pos]) * val % MOD);
x[pos] = val;
if(val >= 2) large.insert(pos);
return calc();
}
int updateY(int pos, int val){
pos++;
y[pos] = val;
st.modify(pos, val, 0, n, 0);
return calc();
}
Compilation message
horses.cpp: In member function 'void BIT::modify(int, ll)':
horses.cpp:46:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(; x < bit.size(); x += lowbit(x)){
| ~~^~~~~~~~~~~~
horses.cpp: In function 'll calc()':
horses.cpp:82:9: warning: unused variable 'cnt' [-Wunused-variable]
82 | int cnt = 0;
| ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:128:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
128 | return ans;
| ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:136:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
136 | return calc();
| ~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:143:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
143 | return calc();
| ~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
216 KB |
Output is correct |
10 |
Correct |
1 ms |
216 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
3 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
204 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
980 ms |
44316 KB |
Output is correct |
2 |
Correct |
479 ms |
44276 KB |
Output is correct |
3 |
Correct |
508 ms |
44228 KB |
Output is correct |
4 |
Correct |
499 ms |
44320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
3 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
3 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
3 ms |
332 KB |
Output is correct |
33 |
Correct |
108 ms |
19996 KB |
Output is correct |
34 |
Correct |
120 ms |
20036 KB |
Output is correct |
35 |
Correct |
307 ms |
43456 KB |
Output is correct |
36 |
Correct |
287 ms |
43356 KB |
Output is correct |
37 |
Correct |
149 ms |
19992 KB |
Output is correct |
38 |
Correct |
204 ms |
31840 KB |
Output is correct |
39 |
Correct |
118 ms |
19876 KB |
Output is correct |
40 |
Correct |
251 ms |
43420 KB |
Output is correct |
41 |
Correct |
119 ms |
19876 KB |
Output is correct |
42 |
Correct |
128 ms |
19876 KB |
Output is correct |
43 |
Correct |
259 ms |
43288 KB |
Output is correct |
44 |
Correct |
258 ms |
43296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
3 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
1014 ms |
44276 KB |
Output is correct |
34 |
Correct |
467 ms |
44320 KB |
Output is correct |
35 |
Correct |
471 ms |
44288 KB |
Output is correct |
36 |
Correct |
496 ms |
44332 KB |
Output is correct |
37 |
Correct |
109 ms |
20000 KB |
Output is correct |
38 |
Correct |
117 ms |
20040 KB |
Output is correct |
39 |
Correct |
296 ms |
43536 KB |
Output is correct |
40 |
Correct |
269 ms |
43332 KB |
Output is correct |
41 |
Correct |
141 ms |
20164 KB |
Output is correct |
42 |
Correct |
205 ms |
31900 KB |
Output is correct |
43 |
Correct |
104 ms |
19840 KB |
Output is correct |
44 |
Correct |
258 ms |
43384 KB |
Output is correct |
45 |
Correct |
122 ms |
19892 KB |
Output is correct |
46 |
Correct |
146 ms |
19876 KB |
Output is correct |
47 |
Correct |
252 ms |
43308 KB |
Output is correct |
48 |
Correct |
253 ms |
43264 KB |
Output is correct |
49 |
Correct |
225 ms |
21968 KB |
Output is correct |
50 |
Correct |
210 ms |
21896 KB |
Output is correct |
51 |
Correct |
490 ms |
44276 KB |
Output is correct |
52 |
Correct |
365 ms |
44344 KB |
Output is correct |
53 |
Correct |
491 ms |
21856 KB |
Output is correct |
54 |
Correct |
407 ms |
34768 KB |
Output is correct |
55 |
Correct |
179 ms |
19988 KB |
Output is correct |
56 |
Correct |
359 ms |
44296 KB |
Output is correct |
57 |
Correct |
292 ms |
20820 KB |
Output is correct |
58 |
Correct |
394 ms |
20776 KB |
Output is correct |
59 |
Correct |
256 ms |
43332 KB |
Output is correct |