#include "towers.h"
#include "bits/stdc++.h"
#include <utility>
#include <vector>
std::vector<int> a;
std::vector<std::vector<int>> binT;
std::vector<int> sufMin;
std::vector<int> preMin;
int maxI = 0;
void init(int N, std::vector<int> H) {
using namespace std;
a = std::move(H);
binT.clear();
sufMin.clear();
preMin.clear();
}
void binJ(std::vector<int> st) {
using namespace std;
binT = vector<vector<int>>(20, vector<int>(st.size() + 1));
for (int i = 0; i < st.size(); ++i) {
binT[0][i] = st[i];
}
binT[0].back() = st.size();
for (int i = 1; i < 20; ++i) {
for (int j = 0; j < st.size() + 1; ++j) {
binT[i][j] = binT[i - 1][binT[i - 1][j]];
}
}
}
int max_towers(int L, int R, int D) {
using namespace std;
if (binT.empty()) {
vector<pair<int,int>> rang(a.size());
vector<int> st;
for (int i = 0; i < a.size(); ++i) {
while (!st.empty() && a[i] >= a[st.back()]) st.pop_back();
auto ne = lower_bound(st.rbegin(), st.rend(), a[i] + D, [&](int l, int r){return a[l] < r;});
if (ne == st.rend()) {
rang[i].first = -1;
} else rang[i].first = *ne;
st.push_back(i);
}
st.clear();
for (int i = a.size() - 1; i >=0; --i) {
while (!st.empty() && a[i] >= a[st.back()]) st.pop_back();
auto ne = lower_bound(st.rbegin(), st.rend(), a[i] + D, [&](int l, int r){return a[l] < r;});
if (ne == st.rend()) {
rang[i].second = a.size();
} else rang[i].second = *ne;
st.push_back(i);
}
sufMin.resize(a.size() + 1);
sufMin.back() = 1e9;
for (int i = a.size() - 1; i >= 0; --i) {
sufMin[i] = min(sufMin[i + 1], rang[i].second);
}
preMin.resize(a.size() + 1);
preMin.front() = -1;
for (int i =0; i < a.size(); ++i) {
preMin[i + 1] = max(preMin[i], rang[i].first);
}
vector<int> evs(a.size(), a.size());
for (int i = a.size() - 1; i >= 0; --i) {
if (rang[i].first >= 0) evs[rang[i].first] = min(evs[rang[i].first], rang[i].second);
if (i < a.size() - 1) evs[i] = min(evs[i], evs[i + 1]);
}
binJ(evs);
}
int ans = 2;
L = sufMin[L];
R = preMin[R + 1];
if (R < L) return 1;
for (int i = 19; i >= 0; --i) {
if (binT[i][L] <= R) {
L = binT[i][L];
ans += 1 << i;
}
}
return ans;
}
Compilation message
towers.cpp: In function 'void binJ(std::vector<int>)':
towers.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int i = 0; i < st.size(); ++i) {
| ~~^~~~~~~~~~~
towers.cpp:31:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int j = 0; j < st.size() + 1; ++j) {
| ~~^~~~~~~~~~~~~~~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:42:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0; i < a.size(); ++i) {
| ~~^~~~~~~~~~
towers.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i =0; i < a.size(); ++i) {
| ~~^~~~~~~~~~
towers.cpp:72:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | if (i < a.size() - 1) evs[i] = min(evs[i], evs[i + 1]);
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
244 ms |
7436 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
832 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
832 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
600 KB |
Output is correct |
36 |
Correct |
12 ms |
7864 KB |
Output is correct |
37 |
Correct |
19 ms |
11580 KB |
Output is correct |
38 |
Correct |
18 ms |
11840 KB |
Output is correct |
39 |
Correct |
17 ms |
11580 KB |
Output is correct |
40 |
Correct |
17 ms |
11576 KB |
Output is correct |
41 |
Correct |
17 ms |
11584 KB |
Output is correct |
42 |
Correct |
19 ms |
11580 KB |
Output is correct |
43 |
Correct |
21 ms |
12220 KB |
Output is correct |
44 |
Correct |
19 ms |
12232 KB |
Output is correct |
45 |
Correct |
19 ms |
12220 KB |
Output is correct |
46 |
Correct |
19 ms |
12048 KB |
Output is correct |
47 |
Correct |
17 ms |
11584 KB |
Output is correct |
48 |
Correct |
17 ms |
11584 KB |
Output is correct |
49 |
Correct |
16 ms |
11968 KB |
Output is correct |
50 |
Correct |
16 ms |
12204 KB |
Output is correct |
51 |
Correct |
19 ms |
12268 KB |
Output is correct |
52 |
Correct |
17 ms |
11732 KB |
Output is correct |
53 |
Correct |
16 ms |
11608 KB |
Output is correct |
54 |
Correct |
16 ms |
11572 KB |
Output is correct |
55 |
Correct |
16 ms |
12220 KB |
Output is correct |
56 |
Correct |
19 ms |
12216 KB |
Output is correct |
57 |
Correct |
19 ms |
11316 KB |
Output is correct |
58 |
Correct |
19 ms |
11580 KB |
Output is correct |
59 |
Correct |
18 ms |
11588 KB |
Output is correct |
60 |
Correct |
19 ms |
11580 KB |
Output is correct |
61 |
Correct |
17 ms |
11584 KB |
Output is correct |
62 |
Correct |
18 ms |
11576 KB |
Output is correct |
63 |
Correct |
17 ms |
11608 KB |
Output is correct |
64 |
Correct |
20 ms |
12140 KB |
Output is correct |
65 |
Correct |
18 ms |
12240 KB |
Output is correct |
66 |
Correct |
18 ms |
11968 KB |
Output is correct |
67 |
Correct |
18 ms |
12392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
461 ms |
11716 KB |
Output is correct |
2 |
Correct |
652 ms |
11580 KB |
Output is correct |
3 |
Correct |
587 ms |
11580 KB |
Output is correct |
4 |
Correct |
617 ms |
11588 KB |
Output is correct |
5 |
Correct |
635 ms |
11588 KB |
Output is correct |
6 |
Correct |
619 ms |
11584 KB |
Output is correct |
7 |
Correct |
655 ms |
11584 KB |
Output is correct |
8 |
Correct |
526 ms |
12100 KB |
Output is correct |
9 |
Correct |
526 ms |
12220 KB |
Output is correct |
10 |
Correct |
540 ms |
12104 KB |
Output is correct |
11 |
Correct |
572 ms |
12208 KB |
Output is correct |
12 |
Correct |
507 ms |
12176 KB |
Output is correct |
13 |
Correct |
510 ms |
12212 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
22 ms |
11588 KB |
Output is correct |
18 |
Correct |
16 ms |
11608 KB |
Output is correct |
19 |
Correct |
17 ms |
11580 KB |
Output is correct |
20 |
Correct |
17 ms |
12140 KB |
Output is correct |
21 |
Correct |
16 ms |
12132 KB |
Output is correct |
22 |
Correct |
17 ms |
11836 KB |
Output is correct |
23 |
Correct |
21 ms |
11572 KB |
Output is correct |
24 |
Correct |
16 ms |
11584 KB |
Output is correct |
25 |
Correct |
15 ms |
12220 KB |
Output is correct |
26 |
Correct |
16 ms |
12212 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
600 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
190 ms |
3080 KB |
2nd lines differ - on the 1st token, expected: '7063', found: '7197' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
832 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
600 KB |
Output is correct |
36 |
Correct |
12 ms |
7864 KB |
Output is correct |
37 |
Correct |
19 ms |
11580 KB |
Output is correct |
38 |
Correct |
18 ms |
11840 KB |
Output is correct |
39 |
Correct |
17 ms |
11580 KB |
Output is correct |
40 |
Correct |
17 ms |
11576 KB |
Output is correct |
41 |
Correct |
17 ms |
11584 KB |
Output is correct |
42 |
Correct |
19 ms |
11580 KB |
Output is correct |
43 |
Correct |
21 ms |
12220 KB |
Output is correct |
44 |
Correct |
19 ms |
12232 KB |
Output is correct |
45 |
Correct |
19 ms |
12220 KB |
Output is correct |
46 |
Correct |
19 ms |
12048 KB |
Output is correct |
47 |
Correct |
17 ms |
11584 KB |
Output is correct |
48 |
Correct |
17 ms |
11584 KB |
Output is correct |
49 |
Correct |
16 ms |
11968 KB |
Output is correct |
50 |
Correct |
16 ms |
12204 KB |
Output is correct |
51 |
Correct |
19 ms |
12268 KB |
Output is correct |
52 |
Correct |
17 ms |
11732 KB |
Output is correct |
53 |
Correct |
16 ms |
11608 KB |
Output is correct |
54 |
Correct |
16 ms |
11572 KB |
Output is correct |
55 |
Correct |
16 ms |
12220 KB |
Output is correct |
56 |
Correct |
19 ms |
12216 KB |
Output is correct |
57 |
Correct |
19 ms |
11316 KB |
Output is correct |
58 |
Correct |
19 ms |
11580 KB |
Output is correct |
59 |
Correct |
18 ms |
11588 KB |
Output is correct |
60 |
Correct |
19 ms |
11580 KB |
Output is correct |
61 |
Correct |
17 ms |
11584 KB |
Output is correct |
62 |
Correct |
18 ms |
11576 KB |
Output is correct |
63 |
Correct |
17 ms |
11608 KB |
Output is correct |
64 |
Correct |
20 ms |
12140 KB |
Output is correct |
65 |
Correct |
18 ms |
12240 KB |
Output is correct |
66 |
Correct |
18 ms |
11968 KB |
Output is correct |
67 |
Correct |
18 ms |
12392 KB |
Output is correct |
68 |
Correct |
461 ms |
11716 KB |
Output is correct |
69 |
Correct |
652 ms |
11580 KB |
Output is correct |
70 |
Correct |
587 ms |
11580 KB |
Output is correct |
71 |
Correct |
617 ms |
11588 KB |
Output is correct |
72 |
Correct |
635 ms |
11588 KB |
Output is correct |
73 |
Correct |
619 ms |
11584 KB |
Output is correct |
74 |
Correct |
655 ms |
11584 KB |
Output is correct |
75 |
Correct |
526 ms |
12100 KB |
Output is correct |
76 |
Correct |
526 ms |
12220 KB |
Output is correct |
77 |
Correct |
540 ms |
12104 KB |
Output is correct |
78 |
Correct |
572 ms |
12208 KB |
Output is correct |
79 |
Correct |
507 ms |
12176 KB |
Output is correct |
80 |
Correct |
510 ms |
12212 KB |
Output is correct |
81 |
Correct |
1 ms |
344 KB |
Output is correct |
82 |
Correct |
1 ms |
600 KB |
Output is correct |
83 |
Correct |
1 ms |
600 KB |
Output is correct |
84 |
Correct |
22 ms |
11588 KB |
Output is correct |
85 |
Correct |
16 ms |
11608 KB |
Output is correct |
86 |
Correct |
17 ms |
11580 KB |
Output is correct |
87 |
Correct |
17 ms |
12140 KB |
Output is correct |
88 |
Correct |
16 ms |
12132 KB |
Output is correct |
89 |
Correct |
17 ms |
11836 KB |
Output is correct |
90 |
Correct |
21 ms |
11572 KB |
Output is correct |
91 |
Correct |
16 ms |
11584 KB |
Output is correct |
92 |
Correct |
15 ms |
12220 KB |
Output is correct |
93 |
Correct |
16 ms |
12212 KB |
Output is correct |
94 |
Correct |
1 ms |
600 KB |
Output is correct |
95 |
Correct |
1 ms |
600 KB |
Output is correct |
96 |
Correct |
1 ms |
600 KB |
Output is correct |
97 |
Correct |
1 ms |
600 KB |
Output is correct |
98 |
Correct |
1 ms |
600 KB |
Output is correct |
99 |
Correct |
1 ms |
600 KB |
Output is correct |
100 |
Correct |
1 ms |
600 KB |
Output is correct |
101 |
Correct |
1 ms |
600 KB |
Output is correct |
102 |
Correct |
1 ms |
600 KB |
Output is correct |
103 |
Correct |
1 ms |
600 KB |
Output is correct |
104 |
Correct |
512 ms |
10356 KB |
Output is correct |
105 |
Correct |
625 ms |
11836 KB |
Output is correct |
106 |
Correct |
655 ms |
11576 KB |
Output is correct |
107 |
Correct |
639 ms |
11576 KB |
Output is correct |
108 |
Correct |
656 ms |
11760 KB |
Output is correct |
109 |
Correct |
689 ms |
11560 KB |
Output is correct |
110 |
Correct |
647 ms |
11720 KB |
Output is correct |
111 |
Correct |
523 ms |
12216 KB |
Output is correct |
112 |
Correct |
572 ms |
12360 KB |
Output is correct |
113 |
Correct |
568 ms |
12216 KB |
Output is correct |
114 |
Correct |
572 ms |
11968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
244 ms |
7436 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |