#include "towers.h"
#include "bits/stdc++.h"
using namespace std;
struct SegTeRan {
vector<int> a;
int get(int l, int r, int i, int lq, int rq) {
if (r <= lq || rq <= l) return 0;
if (lq <= l && r <= rq) return a[i];
int m = (l + r)/2;
return max(get(l, m, 2*i + 1, lq, rq), get(m, r, 2*i + 2, lq, rq));
}
int set(int l, int r, int i, int k, int v) {
if (k < l || r <= k) return a[i];
if (l + 1 == r) return a[i] = v;
int m = (l + r)/2;
return a[i] = max(set(l, m, 2*i + 1, k, v), set(m, r, 2*i + 2, k, v));
}
};
struct SegTeMa{
vector<int> a;
int build(int l, int r, int i, vector<int>& in) {
if (l + 1 == r) return a[i] = in[l];
int m = (l + r)/2;
return a[i] = max(build(l, m, 2*i + 1, in), build(m, r, 2*i + 2, in));
}
int firLe(int l, int r, int i, int k, int hi) {
if (l > k) return -1;
if (a[i] < hi) return -1;
if (l + 1 == r) return l;
int m = (l + r)/2;
int reR = firLe(m, r, 2*i + 2, k, hi);
if (reR != -1) return reR;
return firLe(l, m, 2*i + 1, k, hi);
}
int firRi(int l, int r, int i, int k, int hi) {
if (r <= k) return -1;
if (a[i] < hi) return -1;
if (l + 1 == r) return l;
int m = (l + r)/2;
int reR = firRi(l, m, 2*i + 1, k, hi);
if (reR != -1) return reR;
return firRi(m, r, 2*i + 2, k, hi);
}
};
struct Node {
int l, r, leR, riR, su;
};
struct SegTePer{
vector<Node> a;
void build(int i, int l, int r) {
a[i].leR = l; a[i].riR = r; a[i].su = 0;
if (l + 1 == r) return;
int m = (l + r)/2;
a[i].l = a.size();
a.push_back({});
build(a[i].l, l, m);
a[i].r = a.size();
a.push_back({});
build(a[i].r, m, r);
}
int inc(int i, int k) {
if (a[i].leR > k || a[i].riR <= k) return i;
if (a[i].leR + 1 == a[i].riR) {
a.push_back(a[i]);
a.back().su++;
return a.size() - 1;
}
int le = inc(a[i].l, k), ri = inc(a[i].r, k);
a.push_back({le, ri, a[i].leR, a[i].riR, a[le].su + a[ri].su});
return a.size() - 1;
}
int get(int i, int lq, int rq) {
if (a[i].riR <= lq || rq <= a[i].leR) return 0;
if (lq <= a[i].leR && a[i].riR <= rq) return a[i].su;
return get(a[i].l, lq, rq) + get(a[i].r, lq, rq);
}
};
SegTePer perSe;
vector<pair<int,int>> whi;
void init(int N, std::vector<int> H) {
SegTeMa maSe{vector<int>(4*N)};
SegTeRan raSe{vector<int>(4*N, 0)};
maSe.build(0, N, 0, H);
vector<int> o(N);
std::iota(o.begin(), o.end(),0);
std::sort(o.begin(), o.end(), [&](int l, int r){return H[l] < H[r];});
vector<pair<int,int>> ch;
for (int i = 0; i < N; ++i) {
int l = 0, r = 1e9 + 1;
while (l + 1 < r) {
int m = l + (r - l)/2;
int leB = maSe.firLe(0, N, 0, o[i], H[o[i]] + m), reB = maSe.firRi(0, N, 0, o[i], H[o[i]] + m);
if (leB == -1) leB = 0;
if (reB == -1) reB = N;
if (raSe.get(0, N, 0, leB, reB) < m) l = m;
else r = m;
}
raSe.set(0, N, 0, o[i], l);
ch.push_back({l, o[i]});
}
std::sort(ch.begin(), ch.end(), greater<>());
perSe.a.push_back({});
whi.push_back({1e9 + 1, 0});
perSe.build(0, 0, N);
for (int i = 0; i < N; ++i) {
whi.push_back({ch[i].first, perSe.inc(whi.back().second, ch[i].second)});
}
}
int max_towers(int L, int R, int D) {
int to = std::lower_bound(whi.rbegin(), whi.rend(),make_pair(D, 0))->second;
return perSe.get(to, L, R + 1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
508 ms |
45552 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
7 ms |
1128 KB |
Output is correct |
3 |
Correct |
7 ms |
1184 KB |
Output is correct |
4 |
Correct |
7 ms |
1184 KB |
Output is correct |
5 |
Correct |
7 ms |
1184 KB |
Output is correct |
6 |
Correct |
7 ms |
1184 KB |
Output is correct |
7 |
Incorrect |
8 ms |
1184 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
7 ms |
1128 KB |
Output is correct |
3 |
Correct |
7 ms |
1184 KB |
Output is correct |
4 |
Correct |
7 ms |
1184 KB |
Output is correct |
5 |
Correct |
7 ms |
1184 KB |
Output is correct |
6 |
Correct |
7 ms |
1184 KB |
Output is correct |
7 |
Incorrect |
8 ms |
1184 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
941 ms |
47400 KB |
1st lines differ - on the 1st token, expected: '11903', found: '11902' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
12600 KB |
Output is correct |
2 |
Correct |
972 ms |
47656 KB |
Output is correct |
3 |
Correct |
1045 ms |
48240 KB |
Output is correct |
4 |
Correct |
1050 ms |
48172 KB |
Output is correct |
5 |
Correct |
1071 ms |
49060 KB |
Output is correct |
6 |
Correct |
1039 ms |
47920 KB |
Output is correct |
7 |
Correct |
1151 ms |
48176 KB |
Output is correct |
8 |
Correct |
1016 ms |
48176 KB |
Output is correct |
9 |
Correct |
993 ms |
47620 KB |
Output is correct |
10 |
Correct |
1056 ms |
47792 KB |
Output is correct |
11 |
Correct |
1168 ms |
48600 KB |
Output is correct |
12 |
Correct |
488 ms |
48864 KB |
Output is correct |
13 |
Correct |
505 ms |
49264 KB |
Output is correct |
14 |
Correct |
483 ms |
47460 KB |
Output is correct |
15 |
Correct |
383 ms |
47424 KB |
Output is correct |
16 |
Correct |
510 ms |
47916 KB |
Output is correct |
17 |
Correct |
460 ms |
48960 KB |
Output is correct |
18 |
Correct |
484 ms |
48760 KB |
Output is correct |
19 |
Correct |
501 ms |
48680 KB |
Output is correct |
20 |
Correct |
470 ms |
48544 KB |
Output is correct |
21 |
Correct |
518 ms |
48844 KB |
Output is correct |
22 |
Correct |
489 ms |
48068 KB |
Output is correct |
23 |
Correct |
465 ms |
48016 KB |
Output is correct |
24 |
Correct |
362 ms |
49372 KB |
Output is correct |
25 |
Correct |
322 ms |
47420 KB |
Output is correct |
26 |
Correct |
464 ms |
47916 KB |
Output is correct |
27 |
Correct |
376 ms |
48944 KB |
Output is correct |
28 |
Correct |
7 ms |
1184 KB |
Output is correct |
29 |
Correct |
7 ms |
1184 KB |
Output is correct |
30 |
Correct |
7 ms |
1184 KB |
Output is correct |
31 |
Correct |
6 ms |
1184 KB |
Output is correct |
32 |
Correct |
6 ms |
1280 KB |
Output is correct |
33 |
Correct |
3 ms |
832 KB |
Output is correct |
34 |
Correct |
7 ms |
1184 KB |
Output is correct |
35 |
Correct |
7 ms |
1184 KB |
Output is correct |
36 |
Correct |
8 ms |
1184 KB |
Output is correct |
37 |
Correct |
7 ms |
1184 KB |
Output is correct |
38 |
Correct |
7 ms |
1128 KB |
Output is correct |
39 |
Correct |
8 ms |
1184 KB |
Output is correct |
40 |
Correct |
6 ms |
1120 KB |
Output is correct |
41 |
Correct |
6 ms |
1184 KB |
Output is correct |
42 |
Correct |
6 ms |
1184 KB |
Output is correct |
43 |
Correct |
7 ms |
1184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
7 ms |
1128 KB |
Output is correct |
3 |
Correct |
7 ms |
1184 KB |
Output is correct |
4 |
Correct |
7 ms |
1184 KB |
Output is correct |
5 |
Correct |
7 ms |
1184 KB |
Output is correct |
6 |
Correct |
7 ms |
1184 KB |
Output is correct |
7 |
Incorrect |
8 ms |
1184 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
508 ms |
45552 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |