#ifdef NYAOWO
#include "grader.cpp"
#endif
#include "horses.h"
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;
const int MAXN = 500'000;
const int MOD = 1'000'000'007;
const int INF = 2'000'000'000;
#define L(id) ((id) * 2 + 1)
#define R(id) ((id) * 2 + 2)
struct SegTree {
int a[MAXN * 4 + 10];
int b[MAXN * 4 + 10];
void build() {
fill(a, a + sizeof(a) / sizeof(int), 1);
fill(b, b + sizeof(b) / sizeof(int), 1);
}
void upd(int id, int l, int r, int i, int x) {
if(l == r) {
a[id] = x;
b[id] = x;
return;
}
int m = (l + r) / 2;
if(i <= m) upd(L(id), l, m, i, x);
else upd(R(id), m + 1, r, i, x);
a[id] = min(INF, a[L(id)] * a[R(id)]);
b[id] = b[L(id)] * b[R(id)] % MOD;
}
int qry(int id, int l, int r, int L, int R) {
if(l >= L && r <= R) return a[id];
int m = (l + r) / 2;
int res = 1;
if(L <= m) res = min(INF, res * qry(L(id), l, m, L, R));
if(R > m) res = min(INF, res * qry(R(id), m + 1, r, L, R));
return res;
}
int qry_mod(int id, int l, int r, int L, int R) {
if(l >= L && r <= R) return b[id];
int m = (l + r) / 2;
int res = 1;
if(L <= m) res *= qry_mod(L(id), l, m, L, R);
if(R > m) res *= qry_mod(R(id), m + 1, r, L, R);
return res % MOD;
}
} seg;
int n;
int x[MAXN + 10];
int y[MAXN + 10];
struct SegTree2 {
bool smol(const int &a, const int &b) {
if(a == b) return false;
if(a > b) return !smol(b, a);
return y[a] < seg.qry(0, 0, n - 1, a + 1, b) * y[b];
}
int zzzz(const int &a, const int &b) {
if(smol(a, b)) return b;
return a;
}
int mx[MAXN + 10];
void build(int id, int l, int r) {
if(l == r) {
mx[id] = l;
return;
}
int m = (l + r) / 2;
build(L(id), l, m);
build(R(id), m + 1, r);
mx[id] = zzzz(mx[L(id)], mx[R(id)]);
}
void upd(int id, int l, int r, int i) {
if(l == r) return;
int m = (l + r) / 2;
if(i <= m) upd(L(id), l, m, i);
else upd(R(id), m + 1, r, i);
mx[id] = zzzz(mx[L(id)], mx[R(id)]);
}
} uwu;
int32_t eval(int pos) {
return (int32_t)(y[pos] * seg.qry_mod(0, 0, n - 1, 0, pos) % MOD);
}
int32_t solve() {
int pos = uwu.mx[0];
return eval(pos);
}
int32_t init(int32_t N, int32_t X[], int32_t Y[]) {
n = N;
seg.build();
For(i, 0, n - 1) {
x[i] = X[i];
seg.upd(0, 0, n - 1, i, x[i]);
}
For(i, 0, n - 1) {
y[i] = Y[i];
}
uwu.build(0, 0, n - 1);
return solve();
}
int32_t updateX(int32_t pos, int32_t val) {
x[pos] = val;
seg.upd(0, 0, n - 1, pos, val);
// uwu.upd(0, 0, n - 1, pos);
uwu.build(0, 0, n - 1);
return solve();
}
int32_t updateY(int32_t pos, int32_t val) {
y[pos] = val;
// uwu.upd(0, 0, n - 1, pos);
uwu.build(0, 0, n - 1);
return solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
31592 KB |
Output is correct |
2 |
Correct |
14 ms |
31572 KB |
Output is correct |
3 |
Correct |
11 ms |
31572 KB |
Output is correct |
4 |
Correct |
12 ms |
31532 KB |
Output is correct |
5 |
Correct |
12 ms |
31540 KB |
Output is correct |
6 |
Correct |
12 ms |
31572 KB |
Output is correct |
7 |
Correct |
12 ms |
31572 KB |
Output is correct |
8 |
Correct |
12 ms |
31572 KB |
Output is correct |
9 |
Correct |
12 ms |
31596 KB |
Output is correct |
10 |
Correct |
14 ms |
31572 KB |
Output is correct |
11 |
Correct |
15 ms |
31528 KB |
Output is correct |
12 |
Correct |
12 ms |
31572 KB |
Output is correct |
13 |
Correct |
12 ms |
31608 KB |
Output is correct |
14 |
Correct |
12 ms |
31572 KB |
Output is correct |
15 |
Correct |
13 ms |
31540 KB |
Output is correct |
16 |
Correct |
12 ms |
31552 KB |
Output is correct |
17 |
Correct |
12 ms |
31584 KB |
Output is correct |
18 |
Correct |
12 ms |
31560 KB |
Output is correct |
19 |
Correct |
12 ms |
31604 KB |
Output is correct |
20 |
Correct |
12 ms |
31604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
31572 KB |
Output is correct |
2 |
Correct |
12 ms |
31572 KB |
Output is correct |
3 |
Correct |
13 ms |
31608 KB |
Output is correct |
4 |
Correct |
12 ms |
31572 KB |
Output is correct |
5 |
Correct |
12 ms |
31516 KB |
Output is correct |
6 |
Correct |
12 ms |
31572 KB |
Output is correct |
7 |
Correct |
13 ms |
31516 KB |
Output is correct |
8 |
Correct |
12 ms |
31584 KB |
Output is correct |
9 |
Correct |
12 ms |
31572 KB |
Output is correct |
10 |
Correct |
12 ms |
31568 KB |
Output is correct |
11 |
Correct |
12 ms |
31572 KB |
Output is correct |
12 |
Correct |
13 ms |
31568 KB |
Output is correct |
13 |
Correct |
12 ms |
31632 KB |
Output is correct |
14 |
Correct |
15 ms |
31588 KB |
Output is correct |
15 |
Correct |
12 ms |
31572 KB |
Output is correct |
16 |
Correct |
15 ms |
31540 KB |
Output is correct |
17 |
Correct |
15 ms |
31572 KB |
Output is correct |
18 |
Correct |
12 ms |
31572 KB |
Output is correct |
19 |
Correct |
13 ms |
31572 KB |
Output is correct |
20 |
Correct |
12 ms |
31636 KB |
Output is correct |
21 |
Correct |
15 ms |
31532 KB |
Output is correct |
22 |
Correct |
12 ms |
31572 KB |
Output is correct |
23 |
Correct |
71 ms |
31660 KB |
Output is correct |
24 |
Correct |
69 ms |
31572 KB |
Output is correct |
25 |
Correct |
67 ms |
31664 KB |
Output is correct |
26 |
Correct |
57 ms |
31640 KB |
Output is correct |
27 |
Correct |
77 ms |
31660 KB |
Output is correct |
28 |
Correct |
63 ms |
31644 KB |
Output is correct |
29 |
Correct |
70 ms |
31612 KB |
Output is correct |
30 |
Correct |
64 ms |
31668 KB |
Output is correct |
31 |
Correct |
68 ms |
31656 KB |
Output is correct |
32 |
Correct |
82 ms |
31664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1575 ms |
47148 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
31572 KB |
Output is correct |
2 |
Correct |
14 ms |
31512 KB |
Output is correct |
3 |
Correct |
12 ms |
31572 KB |
Output is correct |
4 |
Correct |
13 ms |
31516 KB |
Output is correct |
5 |
Correct |
17 ms |
31572 KB |
Output is correct |
6 |
Correct |
13 ms |
31600 KB |
Output is correct |
7 |
Correct |
15 ms |
31572 KB |
Output is correct |
8 |
Correct |
15 ms |
31572 KB |
Output is correct |
9 |
Correct |
15 ms |
31524 KB |
Output is correct |
10 |
Correct |
12 ms |
31580 KB |
Output is correct |
11 |
Correct |
12 ms |
31600 KB |
Output is correct |
12 |
Correct |
13 ms |
31572 KB |
Output is correct |
13 |
Correct |
13 ms |
31572 KB |
Output is correct |
14 |
Correct |
13 ms |
31628 KB |
Output is correct |
15 |
Correct |
13 ms |
31556 KB |
Output is correct |
16 |
Correct |
12 ms |
31572 KB |
Output is correct |
17 |
Correct |
12 ms |
31552 KB |
Output is correct |
18 |
Correct |
12 ms |
31572 KB |
Output is correct |
19 |
Correct |
13 ms |
31624 KB |
Output is correct |
20 |
Correct |
12 ms |
31572 KB |
Output is correct |
21 |
Correct |
12 ms |
31572 KB |
Output is correct |
22 |
Correct |
17 ms |
31616 KB |
Output is correct |
23 |
Correct |
68 ms |
31672 KB |
Output is correct |
24 |
Correct |
68 ms |
31656 KB |
Output is correct |
25 |
Correct |
59 ms |
31572 KB |
Output is correct |
26 |
Correct |
58 ms |
31664 KB |
Output is correct |
27 |
Correct |
70 ms |
31604 KB |
Output is correct |
28 |
Correct |
66 ms |
31656 KB |
Output is correct |
29 |
Correct |
72 ms |
31656 KB |
Output is correct |
30 |
Correct |
64 ms |
31672 KB |
Output is correct |
31 |
Correct |
69 ms |
31572 KB |
Output is correct |
32 |
Correct |
69 ms |
31568 KB |
Output is correct |
33 |
Execution timed out |
1537 ms |
47336 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
31572 KB |
Output is correct |
2 |
Correct |
15 ms |
31576 KB |
Output is correct |
3 |
Correct |
12 ms |
31572 KB |
Output is correct |
4 |
Correct |
13 ms |
31572 KB |
Output is correct |
5 |
Correct |
13 ms |
31528 KB |
Output is correct |
6 |
Correct |
12 ms |
31556 KB |
Output is correct |
7 |
Correct |
12 ms |
31640 KB |
Output is correct |
8 |
Correct |
13 ms |
31592 KB |
Output is correct |
9 |
Correct |
12 ms |
31584 KB |
Output is correct |
10 |
Correct |
13 ms |
31572 KB |
Output is correct |
11 |
Correct |
15 ms |
31596 KB |
Output is correct |
12 |
Correct |
15 ms |
31576 KB |
Output is correct |
13 |
Correct |
12 ms |
31552 KB |
Output is correct |
14 |
Correct |
12 ms |
31588 KB |
Output is correct |
15 |
Correct |
16 ms |
31572 KB |
Output is correct |
16 |
Correct |
13 ms |
31600 KB |
Output is correct |
17 |
Correct |
13 ms |
31572 KB |
Output is correct |
18 |
Correct |
13 ms |
31572 KB |
Output is correct |
19 |
Correct |
13 ms |
31572 KB |
Output is correct |
20 |
Correct |
13 ms |
31572 KB |
Output is correct |
21 |
Correct |
13 ms |
31540 KB |
Output is correct |
22 |
Correct |
12 ms |
31572 KB |
Output is correct |
23 |
Correct |
70 ms |
31656 KB |
Output is correct |
24 |
Correct |
69 ms |
31672 KB |
Output is correct |
25 |
Correct |
67 ms |
31572 KB |
Output is correct |
26 |
Correct |
57 ms |
31668 KB |
Output is correct |
27 |
Correct |
73 ms |
31680 KB |
Output is correct |
28 |
Correct |
63 ms |
31656 KB |
Output is correct |
29 |
Correct |
85 ms |
31572 KB |
Output is correct |
30 |
Correct |
64 ms |
31664 KB |
Output is correct |
31 |
Correct |
70 ms |
31672 KB |
Output is correct |
32 |
Correct |
69 ms |
31572 KB |
Output is correct |
33 |
Execution timed out |
1580 ms |
47220 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |