#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> h;
vector<int> incers;
int n;
void init(int N, vector<int> H) {
n = N;
h = H;
for (int i = 0; i < n - 1; i++) {
if (h[i] < h[i + 1]) {
incers.push_back(i);
}
}
incers.push_back(n);
}
bool processed = false;
vector<int> nxt, dow;
int max_towers(int l, int r, int D) {
if (!processed) {
processed = true;
deque<pair<int, int>> st;
nxt.assign(n + 1, n);
dow.assign(n + 1, n);
for (int i = n - 1; i >= 0; i--) {
while (!st.empty() && h[st.front().second] <= h[i]) st.pop_front();
st.push_front({h[i], i});
auto p = lower_bound(st.begin(), st.end(), pair{h[i] + D, -1});
if (p != st.end()) {
nxt[i] = p->second;
}
}
for (int i = n - 2; i >= 0; i--) {
nxt[i] = min(nxt[i], nxt[i + 1]);
}
st.clear();
for (int i = n - 1; i >= 0; i--) {
while (!st.empty() && h[st.front().second] >= h[i]) st.pop_back();
st.push_back({h[i], i});
auto p = lower_bound(st.begin(), st.end(), pair{h[i] - D + 1, -1});
if (p != st.begin()) {
p--;
dow[i] = p->second;
}
}
for (int i = n - 2; i >= 0; i--) {
dow[i] = min(dow[i], dow[i + 1]);
}
}
// for (int i = 0; i < n; i++) {
// cout << nxt[i] << " " << dow[i] << "\n";
// }
int p = *lower_bound(incers.begin(), incers.end(), l);
int s = 0;
while (p < r) {
if (s % 2 == 0) {
p = nxt[p];
if (p <= r) {
s++;
}
} else {
p = dow[p];
if (p <= r) {
s++;
}
}
}
return s / 2 + 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
349 ms |
1844 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '8' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '8' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1342 ms |
2616 KB |
1st lines differ - on the 1st token, expected: '11903', found: '2493' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
386 ms |
720 KB |
1st lines differ - on the 1st token, expected: '7197', found: '1033' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '8' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
349 ms |
1844 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |