#include "horses.h"
#include "bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;
const int md = (int) 1e9 + 7;
struct node {
long double mx = 0, lazy = 0;
};
struct node2 {
int ans = 1, lazy = 1;
};
int n;
int x[N], y[N];
node seg[N * 2];
node2 seg2[N * 2];
int mul(int a, int b) {
return (int) ((long long) a * b % md);
}
inline int inv(int a) {
a %= md;
if (a < 0) a += md;
int b = md, u = 0, v = 1;
while (a) {
int t = b / a;
b -= t * a; swap(a, b);
u -= t * v; swap(u, v);
}
assert(b == 1);
if (u < 0) u += md;
return u;
}
void push(int nd, int l, int r) {
if (!seg[nd].lazy) return;
seg[nd].mx += seg[nd].lazy;
if (l != r) {
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
seg[nd + 1].lazy += seg[nd].lazy;
seg[rs].lazy += seg[nd].lazy;
}
seg[nd].lazy = 0;
}
void push2(int nd, int l, int r) {
if (seg2[nd].lazy == 1) return;
if (l == r) {
seg2[nd].ans = mul(seg2[nd].ans, seg2[nd].lazy);
} else {
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
seg2[nd + 1].lazy = mul(seg2[nd + 1].lazy, seg2[nd].lazy);
seg2[rs].lazy = mul(seg2[rs].lazy, seg2[nd].lazy);
}
seg2[nd].lazy = 1;
}
void upd(int nd, int l, int r, int s, int e, long double v) {
push(nd, l, r);
if (l >= s && r <= e) {
seg[nd].lazy = v;
push(nd, l, r);
return;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (mid >= e) {
upd(nd + 1, l, mid, s, e, v);
push(rs, mid + 1, r);
} else {
if (mid < s) {
upd(rs, mid + 1, r, s, e, v);
push(nd + 1, l, mid);
} else {
upd(nd + 1, l, mid, s, e, v);
upd(rs, mid + 1, r, s, e, v);
}
}
seg[nd].mx = max(seg[nd + 1].mx, seg[rs].mx);
}
void upd2(int nd, int l, int r, int s, int e, int v) {
push2(nd, l, r);
if (l >= s && r <= e) {
seg2[nd].lazy = v;
push2(nd, l, r);
return;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (mid >= e) {
upd2(nd + 1, l, mid, s, e, v);
push2(rs, mid + 1, r);
} else {
if (mid < s) {
upd2(rs, mid + 1, r, s, e, v);
push2(nd + 1, l, mid);
} else {
upd2(nd + 1, l, mid, s, e, v);
upd2(rs, mid + 1, r, s, e, v);
}
}
}
int get(int nd, int l, int r) {
if (l == r) {
return l;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
push(nd + 1, l, mid);
push(rs, mid + 1, r);
if (seg[nd + 1].mx < seg[rs].mx) {
return get(rs, mid + 1, r);
} else {
return get(nd + 1, l, mid);
}
}
int get2(int nd, int l, int r, int p) {
push2(nd, l, r);
if (l == r) {
return seg2[nd].ans;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (p <= mid) {
return get2(nd + 1, l, mid, p);
} else {
return get2(rs, mid + 1, r, p);
}
}
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];
upd(0, 0, n - 1, i, i, log2(1.0L * y[i]));
upd2(0, 0, n - 1, i, i, y[i]);
upd(0, 0, n - 1, i, n - 1, log2(1.0L * x[i]));
upd2(0, 0, n - 1, i, n - 1, x[i]);
}
return get2(0, 0, n - 1, get(0, 0, n - 1));
}
int updateX(int pos, int val) {
upd(0, 0, n - 1, pos, n - 1, -log2(1.0L * x[pos]));
upd2(0, 0, n - 1, pos, n - 1, inv(x[pos]));
x[pos] = val;
upd(0, 0, n - 1, pos, n - 1, +log2(1.0L * x[pos]));
upd2(0, 0, n - 1, pos, n - 1, x[pos]);
return get2(0, 0, n - 1, get(0, 0, n - 1));
}
int updateY(int pos, int val) {
upd(0, 0, n - 1, pos, pos, -log2(1.0L * y[pos]));
upd2(0, 0, n - 1, pos, pos, inv(y[pos]));
y[pos] = val;
upd(0, 0, n - 1, pos, pos, +log2(1.0L * y[pos]));
upd2(0, 0, n - 1, pos, pos, y[pos]);
return get2(0, 0, n - 1, get(0, 0, n - 1));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 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 |
4692 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 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 |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 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 |
4440 KB |
Output is correct |
17 |
Correct |
1 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4640 KB |
Output is correct |
19 |
Correct |
1 ms |
4440 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 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 |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 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 |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
3 ms |
4444 KB |
Output is correct |
24 |
Correct |
3 ms |
4440 KB |
Output is correct |
25 |
Correct |
4 ms |
4444 KB |
Output is correct |
26 |
Correct |
3 ms |
4440 KB |
Output is correct |
27 |
Correct |
3 ms |
4616 KB |
Output is correct |
28 |
Correct |
3 ms |
4440 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
3 ms |
4444 KB |
Output is correct |
31 |
Correct |
3 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
886 ms |
48272 KB |
Output is correct |
2 |
Correct |
1153 ms |
60936 KB |
Output is correct |
3 |
Correct |
1055 ms |
51960 KB |
Output is correct |
4 |
Correct |
1107 ms |
55868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 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 |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 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 |
3 ms |
4444 KB |
Output is correct |
24 |
Correct |
4 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
3 ms |
4444 KB |
Output is correct |
27 |
Correct |
3 ms |
4444 KB |
Output is correct |
28 |
Correct |
3 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4440 KB |
Output is correct |
30 |
Correct |
3 ms |
4440 KB |
Output is correct |
31 |
Correct |
2 ms |
4440 KB |
Output is correct |
32 |
Correct |
2 ms |
4440 KB |
Output is correct |
33 |
Correct |
658 ms |
47352 KB |
Output is correct |
34 |
Correct |
643 ms |
51388 KB |
Output is correct |
35 |
Correct |
743 ms |
58340 KB |
Output is correct |
36 |
Correct |
725 ms |
58172 KB |
Output is correct |
37 |
Correct |
641 ms |
49380 KB |
Output is correct |
38 |
Correct |
688 ms |
50256 KB |
Output is correct |
39 |
Correct |
623 ms |
49496 KB |
Output is correct |
40 |
Correct |
743 ms |
53188 KB |
Output is correct |
41 |
Correct |
619 ms |
49452 KB |
Output is correct |
42 |
Correct |
628 ms |
49340 KB |
Output is correct |
43 |
Correct |
692 ms |
53712 KB |
Output is correct |
44 |
Correct |
696 ms |
53676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4640 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 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 |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 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 |
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 |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
17 |
Correct |
1 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 |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
3 ms |
4444 KB |
Output is correct |
24 |
Correct |
3 ms |
4440 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
3 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4556 KB |
Output is correct |
28 |
Correct |
3 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
3 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4440 KB |
Output is correct |
33 |
Correct |
845 ms |
49940 KB |
Output is correct |
34 |
Correct |
1271 ms |
60956 KB |
Output is correct |
35 |
Correct |
1102 ms |
52128 KB |
Output is correct |
36 |
Correct |
1139 ms |
55928 KB |
Output is correct |
37 |
Correct |
660 ms |
51320 KB |
Output is correct |
38 |
Correct |
639 ms |
51416 KB |
Output is correct |
39 |
Correct |
732 ms |
58120 KB |
Output is correct |
40 |
Correct |
735 ms |
58164 KB |
Output is correct |
41 |
Correct |
636 ms |
49688 KB |
Output is correct |
42 |
Correct |
695 ms |
50472 KB |
Output is correct |
43 |
Correct |
625 ms |
49452 KB |
Output is correct |
44 |
Correct |
726 ms |
53332 KB |
Output is correct |
45 |
Correct |
611 ms |
49532 KB |
Output is correct |
46 |
Correct |
610 ms |
49516 KB |
Output is correct |
47 |
Correct |
727 ms |
53604 KB |
Output is correct |
48 |
Correct |
723 ms |
53684 KB |
Output is correct |
49 |
Correct |
998 ms |
53332 KB |
Output is correct |
50 |
Correct |
921 ms |
53584 KB |
Output is correct |
51 |
Correct |
882 ms |
60192 KB |
Output is correct |
52 |
Correct |
899 ms |
59644 KB |
Output is correct |
53 |
Correct |
891 ms |
51616 KB |
Output is correct |
54 |
Correct |
852 ms |
52096 KB |
Output is correct |
55 |
Correct |
776 ms |
50328 KB |
Output is correct |
56 |
Correct |
929 ms |
55120 KB |
Output is correct |
57 |
Correct |
746 ms |
50920 KB |
Output is correct |
58 |
Correct |
748 ms |
51488 KB |
Output is correct |
59 |
Correct |
691 ms |
53592 KB |
Output is correct |