#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
const int INF = 1e9;
int n;
vi H;
vi St, Dr;
vi DeltaSt, DeltaDr;
struct RMQ {
int n;
vector<vi> A;
RMQ(vi V0) : n((int)V0.size()) {
A.push_back(V0);
for(int k = 1; (1 << k) <= n; ++k) {
A.push_back(A.back());
for(int i = 0; i < n; ++i) {
if(i + (1 << (k - 1)) < n)
A[k][i] = max(A[k][i], A[k - 1][i + (1 << (k - 1))]);
}
}
}
int query(int l, int r) {
int d = 31 - __builtin_clz(r - l + 1);
return max(A[d][l], A[d][r - (1 << d) + 1]);
}
};
pair<vi, vi> descomp(vi A) {
RMQ R(A);
vi Ant(n, -1);
vi Delta(n, INF); /// cel mai mare delta posibil
stack<int> S;
for(int i = 0; i < n; ++i) {
while(!S.empty() && A[S.top()] > A[i]) {
S.pop();
}
if(!S.empty()) {
Ant[i] = S.top();
Delta[i] = R.query(S.top(), i) - A[i];
}
S.push(i);
}
return make_pair(Ant, Delta);
}
vi S;
void init(int N0, vi H0) {
n = N0;
H = H0;
tie(St, DeltaSt) = descomp(H);
reverse(H.begin(), H.end());
tie(Dr, DeltaDr) = descomp(H);
reverse(H.begin(), H.end());
reverse(Dr.begin(), Dr.end());
reverse(DeltaDr.begin(), DeltaDr.end());
for(auto &it : Dr)
it = n - it - 1;
for(int i = 0; i < n; ++i) {
S.push_back(min(DeltaSt[i], DeltaDr[i]));
}
sort(S.begin(), S.end());
// cout << "St: ";
// for(auto it : St) cout << it << " ";
// cout << "\n";
// cout << "DeltaSt: ";
// for(auto it : DeltaSt) cout << it << " ";
// cout << "\n";
// cout << "Dr: ";
// for(auto it : Dr) cout << it << " ";
// cout << "\n";
// cout << "DeltaDr: ";
// for(auto it : DeltaDr) cout << it << " ";
// cout << "\n";
}
int max_towers(int L, int R, int D) {
int v = lower_bound(S.begin(), S.end(), D) - S.begin();
return n - v;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
277 ms |
6668 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
472 ms |
10884 KB |
1st lines differ - on the 1st token, expected: '11903', found: '33010' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
2740 KB |
Output is correct |
2 |
Correct |
667 ms |
10816 KB |
Output is correct |
3 |
Correct |
696 ms |
10812 KB |
Output is correct |
4 |
Correct |
638 ms |
10816 KB |
Output is correct |
5 |
Correct |
697 ms |
10816 KB |
Output is correct |
6 |
Correct |
694 ms |
10808 KB |
Output is correct |
7 |
Correct |
710 ms |
10808 KB |
Output is correct |
8 |
Correct |
590 ms |
10816 KB |
Output is correct |
9 |
Correct |
707 ms |
11328 KB |
Output is correct |
10 |
Correct |
685 ms |
11072 KB |
Output is correct |
11 |
Correct |
633 ms |
11064 KB |
Output is correct |
12 |
Correct |
24 ms |
10816 KB |
Output is correct |
13 |
Correct |
32 ms |
10784 KB |
Output is correct |
14 |
Correct |
25 ms |
10816 KB |
Output is correct |
15 |
Correct |
21 ms |
11308 KB |
Output is correct |
16 |
Correct |
21 ms |
11072 KB |
Output is correct |
17 |
Correct |
39 ms |
10520 KB |
Output is correct |
18 |
Correct |
24 ms |
10804 KB |
Output is correct |
19 |
Correct |
26 ms |
11064 KB |
Output is correct |
20 |
Correct |
33 ms |
10808 KB |
Output is correct |
21 |
Correct |
32 ms |
10808 KB |
Output is correct |
22 |
Correct |
24 ms |
10816 KB |
Output is correct |
23 |
Correct |
26 ms |
10816 KB |
Output is correct |
24 |
Correct |
20 ms |
10816 KB |
Output is correct |
25 |
Correct |
20 ms |
11328 KB |
Output is correct |
26 |
Correct |
20 ms |
11032 KB |
Output is correct |
27 |
Correct |
21 ms |
11320 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
584 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
277 ms |
6668 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |