#include "horses.h"
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); ++i)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; --i)
#define rrep2(i, n, t) for(ll i = ll(n)-1; i >= ll(t); --i)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define SZ(a) int(a.size())
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
const int inf = 1001001001;
const ll linf = 1001001001001001001;
template<class T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int mod = 1000000007;
using S = pair<ll, ll>;
const S e = {1, 0};
constexpr S op(const S &a, const S &b) {
return {a.first * b.first % mod, max(a.second, b.second)};
}
class segtree {
int n;
vector<S> d;
void update(int p) {
d[p] = op(d[2 * p], d[2 * p + 1]);
}
public:
segtree(const vector<S> &init = {}) {
n = 1;
while (n < SZ(init)) n *= 2;
d.assign(2 * n, e);
rep(i, SZ(init)) d[n + i] = init[i];
rrep2(i, n, 1) update(i);
}
void set(int p, const S &x) {
assert(0 <= p and p < n);
p += n;
d[p] = x;
while (p > 1) {
p >>= 1;
update(p);
}
}
S prod(int l, int r) {
assert(0 <= l and l <= r and r <= n);
l += n, r += n;
S res = e;
while (l < r) {
if (l & 1) res = op(res, d[l++]);
if (r & 1) res = op(res, d[--r]);
l >>= 1, r >>= 1;
}
return res;
}
};
int n;
vl x, y;
segtree st;
set<int> bd;
int calc() {
auto it = prev(bd.end());
vector<S> v;
rep(_, 30) {
if (it == bd.begin()) break;
int r = *it, l = *(--it);
v.pb(st.prod(l, r));
}
reverse(all(v));
// for(auto [f,s] : v) cerr << f << ' ' << s << endl;
int mx = 0;
ll now = 1;
rep2(i, 1, SZ(v)) {
now *= v[i].first;
chmin(now, (ll) inf);
if (now * v[i].second > v[mx].second) {
mx = i;
now = 1;
}
}
// cerr << mx << endl;
ll res = st.prod(0, *it).first;
rep(i, mx + 1) {
res *= v[i].first;
res %= mod;
}
res *= v[mx].second;
res %= mod;
return res;
}
int init(int N, int X[], int Y[]) {
n = N;
x = vl(X, X + N);
y = vl(Y, Y + N);
vector<S> init(n);
rep(i, n) init[i] = {x[i], y[i]};
st = segtree(init);
bd.insert(0);
bd.insert(n);
rep2(i, 1, n) if (x[i] > 1) bd.insert(i);
return calc();
}
int updateX(int pos, int val) {
if (pos) {
if (x[pos] > 1 and val == 1) bd.erase(pos);
if (x[pos] == 1 and val > 1) bd.insert(pos);
}
x[pos] = val;
st.set(pos, {x[pos], y[pos]});
return calc();
}
int updateY(int pos, int val) {
y[pos] = val;
st.set(pos, {x[pos], y[pos]});
return calc();
}
Compilation message
horses.cpp: In constructor 'segtree::segtree(const std::vector<std::pair<long long int, long long int> >&)':
horses.cpp:68:31: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
68 | rrep2(i, n, 1) update(i);
| ^
horses.cpp: In function 'int calc()':
horses.cpp:116:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
116 | mx = i;
| ^
horses.cpp:128:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
128 | return res;
| ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:140:43: warning: conversion from 'll' {aka 'long long int'} to 'std::set<int>::value_type' {aka 'int'} may change value [-Wconversion]
140 | rep2(i, 1, n) if (x[i] > 1) bd.insert(i);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
0 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 |
300 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 |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
300 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 |
0 ms |
300 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 |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 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 |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
308 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
436 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
316 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
61912 KB |
Output is correct |
2 |
Correct |
320 ms |
70700 KB |
Output is correct |
3 |
Correct |
259 ms |
61900 KB |
Output is correct |
4 |
Correct |
283 ms |
65840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
0 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 |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
224 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
308 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
444 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
436 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
57 ms |
40124 KB |
Output is correct |
34 |
Correct |
49 ms |
40100 KB |
Output is correct |
35 |
Correct |
228 ms |
70628 KB |
Output is correct |
36 |
Correct |
212 ms |
70472 KB |
Output is correct |
37 |
Correct |
48 ms |
38396 KB |
Output is correct |
38 |
Correct |
108 ms |
50940 KB |
Output is correct |
39 |
Correct |
37 ms |
38276 KB |
Output is correct |
40 |
Correct |
204 ms |
65648 KB |
Output is correct |
41 |
Correct |
34 ms |
38220 KB |
Output is correct |
42 |
Correct |
36 ms |
38372 KB |
Output is correct |
43 |
Correct |
179 ms |
66032 KB |
Output is correct |
44 |
Correct |
177 ms |
66020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
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 |
0 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 |
296 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
396 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
316 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
273 ms |
61852 KB |
Output is correct |
34 |
Correct |
309 ms |
70764 KB |
Output is correct |
35 |
Correct |
311 ms |
61884 KB |
Output is correct |
36 |
Correct |
302 ms |
65696 KB |
Output is correct |
37 |
Correct |
59 ms |
40124 KB |
Output is correct |
38 |
Correct |
61 ms |
40140 KB |
Output is correct |
39 |
Correct |
214 ms |
70612 KB |
Output is correct |
40 |
Correct |
204 ms |
70672 KB |
Output is correct |
41 |
Correct |
46 ms |
38272 KB |
Output is correct |
42 |
Correct |
107 ms |
51016 KB |
Output is correct |
43 |
Correct |
34 ms |
38340 KB |
Output is correct |
44 |
Correct |
196 ms |
65708 KB |
Output is correct |
45 |
Correct |
37 ms |
38332 KB |
Output is correct |
46 |
Correct |
36 ms |
38276 KB |
Output is correct |
47 |
Correct |
196 ms |
66020 KB |
Output is correct |
48 |
Correct |
177 ms |
66248 KB |
Output is correct |
49 |
Correct |
208 ms |
40216 KB |
Output is correct |
50 |
Correct |
197 ms |
40188 KB |
Output is correct |
51 |
Correct |
322 ms |
70944 KB |
Output is correct |
52 |
Correct |
299 ms |
70764 KB |
Output is correct |
53 |
Correct |
211 ms |
38348 KB |
Output is correct |
54 |
Correct |
228 ms |
50992 KB |
Output is correct |
55 |
Correct |
101 ms |
38448 KB |
Output is correct |
56 |
Correct |
327 ms |
65684 KB |
Output is correct |
57 |
Correct |
104 ms |
38348 KB |
Output is correct |
58 |
Correct |
125 ms |
38388 KB |
Output is correct |
59 |
Correct |
171 ms |
66180 KB |
Output is correct |