// In the name of Allah
#include <bits/stdc++.h>
#include "towers.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define Mp make_pair
#define pb push_back
#define endl '\n'
#define sep ' '
const int maxn = 1e5 + 7;
const int maxlg = 20;
const ll oo = 1e9 + 7;
int n;
ll A[maxn]; int L[maxn], R[maxn];
int rmq[maxn][maxlg];
vector<ll> arr; ll sm[maxn];
int GI(ll x) {
return lower_bound(all(arr), x) - arr.begin();
}
ll get_max(int l, int r) {
if (l >= r) return -oo;
int j = __lg(r - l);
return max(rmq[l][j], rmq[r - (1 << j)][j]);
}
void init(int N, vector<int> H) {
n = N;
for (int i = 0; i < n; i++) A[i] = H[i];
for (int i = n - 1; i >= 0; i--) {
rmq[i][0] = A[i];
for (int j = 1; j < maxlg; j++) {
if (i + (1 << j) - 1 >= n) break;
rmq[i][j] = max(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
}
}
for (int i = 0; i < n; i++) {
for (L[i] = i - 1; L[i] != -1 && A[i] <= A[L[i]]; L[i] = L[L[i]]);
}
for (int i = n - 1; i >= 0; i--) {
for (R[i] = i + 1; R[i] != n && A[i] <= A[R[i]]; R[i] = R[R[i]]);
}
for (int i = 0; i < n; i++) {
ll x = oo;
if (L[i] != -1) x = min(x, get_max(L[i] + 1, i) - A[i]);
if (R[i] != n) x = min(x, get_max(i + 1, R[i]) - A[i]);
if (x <= 0) continue;
arr.pb(x);
}
sort(all(arr)); arr.resize(unique(all(arr)) - arr.begin());
for (int i = 0; i < n; i++) {
ll x = oo;
if (L[i] != -1) x = min(x, get_max(L[i] + 1, i) - A[i]);
if (R[i] != n) x = min(x, get_max(i + 1, R[i]) - A[i]);
if (x <= 0) continue;
int j = GI(x); sm[j]++;
}
for (int j = len(arr) - 2; j >= 0; j--) sm[j] += sm[j + 1];
}
bool check(int i, int j, int D) {
if (j - i + 1 <= 2) return 0;
int mx = get_max(i + 1, j);
return (mx >= max(A[i], A[j]) + D);
}
int max_towers(int L, int R, int D) {
int j = lower_bound(all(arr), D) - arr.begin();
return sm[j];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
236 ms |
7768 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
373 ms |
11732 KB |
1st lines differ - on the 1st token, expected: '11903', found: '33010' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
5276 KB |
Output is correct |
2 |
Correct |
537 ms |
11732 KB |
Output is correct |
3 |
Correct |
518 ms |
11796 KB |
Output is correct |
4 |
Correct |
585 ms |
11732 KB |
Output is correct |
5 |
Correct |
496 ms |
11732 KB |
Output is correct |
6 |
Correct |
574 ms |
11732 KB |
Output is correct |
7 |
Correct |
540 ms |
11732 KB |
Output is correct |
8 |
Correct |
488 ms |
11096 KB |
Output is correct |
9 |
Correct |
410 ms |
11096 KB |
Output is correct |
10 |
Correct |
518 ms |
11096 KB |
Output is correct |
11 |
Correct |
600 ms |
11092 KB |
Output is correct |
12 |
Correct |
18 ms |
11732 KB |
Output is correct |
13 |
Correct |
19 ms |
11832 KB |
Output is correct |
14 |
Correct |
25 ms |
11732 KB |
Output is correct |
15 |
Correct |
11 ms |
11096 KB |
Output is correct |
16 |
Correct |
11 ms |
11096 KB |
Output is correct |
17 |
Correct |
25 ms |
11476 KB |
Output is correct |
18 |
Correct |
20 ms |
11736 KB |
Output is correct |
19 |
Correct |
18 ms |
11732 KB |
Output is correct |
20 |
Correct |
20 ms |
11852 KB |
Output is correct |
21 |
Correct |
19 ms |
11732 KB |
Output is correct |
22 |
Correct |
20 ms |
11732 KB |
Output is correct |
23 |
Correct |
20 ms |
11720 KB |
Output is correct |
24 |
Correct |
16 ms |
11084 KB |
Output is correct |
25 |
Correct |
11 ms |
11096 KB |
Output is correct |
26 |
Correct |
11 ms |
11096 KB |
Output is correct |
27 |
Correct |
11 ms |
11096 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
0 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
0 ms |
2392 KB |
Output is correct |
36 |
Correct |
1 ms |
2392 KB |
Output is correct |
37 |
Correct |
0 ms |
2392 KB |
Output is correct |
38 |
Correct |
1 ms |
2392 KB |
Output is correct |
39 |
Correct |
1 ms |
2392 KB |
Output is correct |
40 |
Correct |
0 ms |
2392 KB |
Output is correct |
41 |
Correct |
0 ms |
2392 KB |
Output is correct |
42 |
Correct |
1 ms |
2392 KB |
Output is correct |
43 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
236 ms |
7768 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |