#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
namespace {
vector<int> H;
int N;
bool done = false;
vector lift(250000,vector(18,0));
vector leave(250000,0);
void generate(int D) {
if(done)return;
vector<int> L(N+1);
{
deque<pair<int,int>> q;
q.emplace_back(INF,0);
for(int i=1;i<=N;i++) {
while(q.front().first<=H[i])q.pop_front();
int ans = -1;
for(int jump=131072;jump;jump/=2) {
if(ans+jump>=q.size())continue;
if(q[ans+jump].first<H[i]+D)ans+=jump;
}
ans++;
L[i]=q[ans].second;
q.emplace_front(H[i],i);
}
}
vector<int> R(N+1);
{
deque<pair<int,int>> q;
q.emplace_back(INF,N+N+1);
for(int i=N;i;i--) {
while(q.front().first<=H[i])q.pop_front();
int ans = -1;
for(int jump=131072;jump;jump/=2) {
if(ans+jump>=q.size())continue;
if(q[ans+jump].first<H[i]+D)ans+=jump;
}
ans++;
R[i]=q[ans].second;
q.emplace_front(H[i],i);
}
}
int min_node_direct = N+N+1;
int min_node_sub = N+N+1;
int min_node_leave = N+N+1;
vector<vector<int>> q(N+1);
vector<vector<int>> ql(N+1);
for(int i=N;i;i--) {
for(int&j:q[i]) {
min_node_direct = min(min_node_direct,j);
min_node_sub = min(min_node_sub,j);
}
for(int&j:ql[i]) {
min_node_leave= min(min_node_leave,j);
}
min_node_direct=min(min_node_direct,R[i]);
leave[i]=min_node_leave;
lift[i+N][0]=min_node_direct;
lift[i][0]=min_node_sub;
assert(min_node_sub>i);
q[L[i]].emplace_back(R[i]);
ql[L[i]].emplace_back(i);
}
lift[N+N+1][0]=N+N+1;
for(int bit=1;bit<18;bit++) {
for(int i=1;i<=2*N+1;i++) {
lift[i][bit] = lift[lift[i][bit-1]][bit-1];
}
}
done = true;
}
}
void init(int N,vector<int> H){
H.emplace(H.begin(),-1);
::H = H;
::N = N;
}
int max_towers(int L,int R,int D){
L++;R++;
generate(D);
int x = N+L;
if(lift[x][0]>R)return 1;
int ans = 0;
for(int bit=17;bit>=0;bit--) {
if(lift[x][bit]<=R) {
ans+=(1<<bit);
x=lift[x][bit];
}
}
if(x!=R and leave[x]<=R)ans++;
return ans;
}
Compilation message
towers.cpp: In function 'void {anonymous}::generate(int)':
towers.cpp:23:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if(ans+jump>=q.size())continue;
| ~~~~~~~~^~~~~~~~~~
towers.cpp:39:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(ans+jump>=q.size())continue;
| ~~~~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
373 ms |
31608 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
26712 KB |
Output is correct |
2 |
Correct |
15 ms |
26968 KB |
Output is correct |
3 |
Correct |
18 ms |
26884 KB |
Output is correct |
4 |
Correct |
15 ms |
26968 KB |
Output is correct |
5 |
Correct |
15 ms |
26968 KB |
Output is correct |
6 |
Correct |
17 ms |
26968 KB |
Output is correct |
7 |
Correct |
17 ms |
26968 KB |
Output is correct |
8 |
Correct |
15 ms |
26968 KB |
Output is correct |
9 |
Correct |
15 ms |
26948 KB |
Output is correct |
10 |
Correct |
15 ms |
26964 KB |
Output is correct |
11 |
Correct |
15 ms |
26840 KB |
Output is correct |
12 |
Correct |
15 ms |
26712 KB |
Output is correct |
13 |
Correct |
17 ms |
27016 KB |
Output is correct |
14 |
Correct |
16 ms |
26968 KB |
Output is correct |
15 |
Correct |
15 ms |
27220 KB |
Output is correct |
16 |
Correct |
18 ms |
27040 KB |
Output is correct |
17 |
Correct |
18 ms |
27220 KB |
Output is correct |
18 |
Correct |
17 ms |
26968 KB |
Output is correct |
19 |
Correct |
15 ms |
26968 KB |
Output is correct |
20 |
Correct |
17 ms |
26968 KB |
Output is correct |
21 |
Correct |
16 ms |
26968 KB |
Output is correct |
22 |
Correct |
16 ms |
26968 KB |
Output is correct |
23 |
Correct |
15 ms |
26968 KB |
Output is correct |
24 |
Correct |
16 ms |
26968 KB |
Output is correct |
25 |
Correct |
16 ms |
26900 KB |
Output is correct |
26 |
Correct |
15 ms |
26968 KB |
Output is correct |
27 |
Correct |
23 ms |
26892 KB |
Output is correct |
28 |
Correct |
20 ms |
26816 KB |
Output is correct |
29 |
Correct |
15 ms |
26968 KB |
Output is correct |
30 |
Correct |
17 ms |
26968 KB |
Output is correct |
31 |
Correct |
18 ms |
26968 KB |
Output is correct |
32 |
Correct |
15 ms |
26852 KB |
Output is correct |
33 |
Correct |
15 ms |
26936 KB |
Output is correct |
34 |
Correct |
15 ms |
26968 KB |
Output is correct |
35 |
Correct |
17 ms |
26968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
26712 KB |
Output is correct |
2 |
Correct |
15 ms |
26968 KB |
Output is correct |
3 |
Correct |
18 ms |
26884 KB |
Output is correct |
4 |
Correct |
15 ms |
26968 KB |
Output is correct |
5 |
Correct |
15 ms |
26968 KB |
Output is correct |
6 |
Correct |
17 ms |
26968 KB |
Output is correct |
7 |
Correct |
17 ms |
26968 KB |
Output is correct |
8 |
Correct |
15 ms |
26968 KB |
Output is correct |
9 |
Correct |
15 ms |
26948 KB |
Output is correct |
10 |
Correct |
15 ms |
26964 KB |
Output is correct |
11 |
Correct |
15 ms |
26840 KB |
Output is correct |
12 |
Correct |
15 ms |
26712 KB |
Output is correct |
13 |
Correct |
17 ms |
27016 KB |
Output is correct |
14 |
Correct |
16 ms |
26968 KB |
Output is correct |
15 |
Correct |
15 ms |
27220 KB |
Output is correct |
16 |
Correct |
18 ms |
27040 KB |
Output is correct |
17 |
Correct |
18 ms |
27220 KB |
Output is correct |
18 |
Correct |
17 ms |
26968 KB |
Output is correct |
19 |
Correct |
15 ms |
26968 KB |
Output is correct |
20 |
Correct |
17 ms |
26968 KB |
Output is correct |
21 |
Correct |
16 ms |
26968 KB |
Output is correct |
22 |
Correct |
16 ms |
26968 KB |
Output is correct |
23 |
Correct |
15 ms |
26968 KB |
Output is correct |
24 |
Correct |
16 ms |
26968 KB |
Output is correct |
25 |
Correct |
16 ms |
26900 KB |
Output is correct |
26 |
Correct |
15 ms |
26968 KB |
Output is correct |
27 |
Correct |
23 ms |
26892 KB |
Output is correct |
28 |
Correct |
20 ms |
26816 KB |
Output is correct |
29 |
Correct |
15 ms |
26968 KB |
Output is correct |
30 |
Correct |
17 ms |
26968 KB |
Output is correct |
31 |
Correct |
18 ms |
26968 KB |
Output is correct |
32 |
Correct |
15 ms |
26852 KB |
Output is correct |
33 |
Correct |
15 ms |
26936 KB |
Output is correct |
34 |
Correct |
15 ms |
26968 KB |
Output is correct |
35 |
Correct |
17 ms |
26968 KB |
Output is correct |
36 |
Correct |
47 ms |
32848 KB |
Output is correct |
37 |
Correct |
54 ms |
34836 KB |
Output is correct |
38 |
Correct |
51 ms |
35392 KB |
Output is correct |
39 |
Correct |
45 ms |
34632 KB |
Output is correct |
40 |
Correct |
52 ms |
36160 KB |
Output is correct |
41 |
Correct |
54 ms |
35136 KB |
Output is correct |
42 |
Correct |
57 ms |
36160 KB |
Output is correct |
43 |
Correct |
55 ms |
34112 KB |
Output is correct |
44 |
Correct |
57 ms |
35644 KB |
Output is correct |
45 |
Correct |
46 ms |
34568 KB |
Output is correct |
46 |
Correct |
62 ms |
35136 KB |
Output is correct |
47 |
Correct |
58 ms |
36160 KB |
Output is correct |
48 |
Correct |
54 ms |
36320 KB |
Output is correct |
49 |
Correct |
50 ms |
36160 KB |
Output is correct |
50 |
Correct |
54 ms |
39232 KB |
Output is correct |
51 |
Correct |
48 ms |
34112 KB |
Output is correct |
52 |
Correct |
58 ms |
36124 KB |
Output is correct |
53 |
Correct |
61 ms |
36160 KB |
Output is correct |
54 |
Correct |
57 ms |
36160 KB |
Output is correct |
55 |
Correct |
64 ms |
39232 KB |
Output is correct |
56 |
Correct |
52 ms |
34368 KB |
Output is correct |
57 |
Correct |
54 ms |
34376 KB |
Output is correct |
58 |
Correct |
52 ms |
34876 KB |
Output is correct |
59 |
Correct |
59 ms |
35520 KB |
Output is correct |
60 |
Correct |
54 ms |
36244 KB |
Output is correct |
61 |
Correct |
59 ms |
36156 KB |
Output is correct |
62 |
Correct |
52 ms |
35392 KB |
Output is correct |
63 |
Correct |
65 ms |
36160 KB |
Output is correct |
64 |
Correct |
51 ms |
34112 KB |
Output is correct |
65 |
Correct |
55 ms |
35136 KB |
Output is correct |
66 |
Correct |
46 ms |
34688 KB |
Output is correct |
67 |
Correct |
69 ms |
35316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
596 ms |
36168 KB |
Output is correct |
2 |
Correct |
776 ms |
36168 KB |
Output is correct |
3 |
Correct |
729 ms |
36160 KB |
Output is correct |
4 |
Correct |
725 ms |
36160 KB |
Output is correct |
5 |
Correct |
783 ms |
36160 KB |
Output is correct |
6 |
Correct |
805 ms |
36160 KB |
Output is correct |
7 |
Correct |
767 ms |
36160 KB |
Output is correct |
8 |
Correct |
678 ms |
34116 KB |
Output is correct |
9 |
Correct |
663 ms |
39232 KB |
Output is correct |
10 |
Correct |
670 ms |
34376 KB |
Output is correct |
11 |
Correct |
725 ms |
39268 KB |
Output is correct |
12 |
Correct |
681 ms |
34368 KB |
Output is correct |
13 |
Correct |
733 ms |
39232 KB |
Output is correct |
14 |
Correct |
15 ms |
26764 KB |
Output is correct |
15 |
Correct |
23 ms |
27004 KB |
Output is correct |
16 |
Correct |
17 ms |
26968 KB |
Output is correct |
17 |
Correct |
57 ms |
36160 KB |
Output is correct |
18 |
Correct |
60 ms |
36160 KB |
Output is correct |
19 |
Correct |
56 ms |
36168 KB |
Output is correct |
20 |
Correct |
57 ms |
39232 KB |
Output is correct |
21 |
Correct |
48 ms |
34188 KB |
Output is correct |
22 |
Correct |
66 ms |
36160 KB |
Output is correct |
23 |
Correct |
53 ms |
36160 KB |
Output is correct |
24 |
Correct |
54 ms |
36164 KB |
Output is correct |
25 |
Correct |
58 ms |
39232 KB |
Output is correct |
26 |
Correct |
48 ms |
34368 KB |
Output is correct |
27 |
Correct |
16 ms |
26968 KB |
Output is correct |
28 |
Correct |
16 ms |
26968 KB |
Output is correct |
29 |
Correct |
17 ms |
26968 KB |
Output is correct |
30 |
Correct |
16 ms |
26968 KB |
Output is correct |
31 |
Correct |
15 ms |
26968 KB |
Output is correct |
32 |
Correct |
17 ms |
26968 KB |
Output is correct |
33 |
Correct |
17 ms |
27048 KB |
Output is correct |
34 |
Correct |
16 ms |
26968 KB |
Output is correct |
35 |
Correct |
16 ms |
26968 KB |
Output is correct |
36 |
Correct |
15 ms |
26968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
228 ms |
28968 KB |
2nd lines differ - on the 1st token, expected: '7063', found: '7197' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
26712 KB |
Output is correct |
2 |
Correct |
15 ms |
26968 KB |
Output is correct |
3 |
Correct |
18 ms |
26884 KB |
Output is correct |
4 |
Correct |
15 ms |
26968 KB |
Output is correct |
5 |
Correct |
15 ms |
26968 KB |
Output is correct |
6 |
Correct |
17 ms |
26968 KB |
Output is correct |
7 |
Correct |
17 ms |
26968 KB |
Output is correct |
8 |
Correct |
15 ms |
26968 KB |
Output is correct |
9 |
Correct |
15 ms |
26948 KB |
Output is correct |
10 |
Correct |
15 ms |
26964 KB |
Output is correct |
11 |
Correct |
15 ms |
26840 KB |
Output is correct |
12 |
Correct |
15 ms |
26712 KB |
Output is correct |
13 |
Correct |
17 ms |
27016 KB |
Output is correct |
14 |
Correct |
16 ms |
26968 KB |
Output is correct |
15 |
Correct |
15 ms |
27220 KB |
Output is correct |
16 |
Correct |
18 ms |
27040 KB |
Output is correct |
17 |
Correct |
18 ms |
27220 KB |
Output is correct |
18 |
Correct |
17 ms |
26968 KB |
Output is correct |
19 |
Correct |
15 ms |
26968 KB |
Output is correct |
20 |
Correct |
17 ms |
26968 KB |
Output is correct |
21 |
Correct |
16 ms |
26968 KB |
Output is correct |
22 |
Correct |
16 ms |
26968 KB |
Output is correct |
23 |
Correct |
15 ms |
26968 KB |
Output is correct |
24 |
Correct |
16 ms |
26968 KB |
Output is correct |
25 |
Correct |
16 ms |
26900 KB |
Output is correct |
26 |
Correct |
15 ms |
26968 KB |
Output is correct |
27 |
Correct |
23 ms |
26892 KB |
Output is correct |
28 |
Correct |
20 ms |
26816 KB |
Output is correct |
29 |
Correct |
15 ms |
26968 KB |
Output is correct |
30 |
Correct |
17 ms |
26968 KB |
Output is correct |
31 |
Correct |
18 ms |
26968 KB |
Output is correct |
32 |
Correct |
15 ms |
26852 KB |
Output is correct |
33 |
Correct |
15 ms |
26936 KB |
Output is correct |
34 |
Correct |
15 ms |
26968 KB |
Output is correct |
35 |
Correct |
17 ms |
26968 KB |
Output is correct |
36 |
Correct |
47 ms |
32848 KB |
Output is correct |
37 |
Correct |
54 ms |
34836 KB |
Output is correct |
38 |
Correct |
51 ms |
35392 KB |
Output is correct |
39 |
Correct |
45 ms |
34632 KB |
Output is correct |
40 |
Correct |
52 ms |
36160 KB |
Output is correct |
41 |
Correct |
54 ms |
35136 KB |
Output is correct |
42 |
Correct |
57 ms |
36160 KB |
Output is correct |
43 |
Correct |
55 ms |
34112 KB |
Output is correct |
44 |
Correct |
57 ms |
35644 KB |
Output is correct |
45 |
Correct |
46 ms |
34568 KB |
Output is correct |
46 |
Correct |
62 ms |
35136 KB |
Output is correct |
47 |
Correct |
58 ms |
36160 KB |
Output is correct |
48 |
Correct |
54 ms |
36320 KB |
Output is correct |
49 |
Correct |
50 ms |
36160 KB |
Output is correct |
50 |
Correct |
54 ms |
39232 KB |
Output is correct |
51 |
Correct |
48 ms |
34112 KB |
Output is correct |
52 |
Correct |
58 ms |
36124 KB |
Output is correct |
53 |
Correct |
61 ms |
36160 KB |
Output is correct |
54 |
Correct |
57 ms |
36160 KB |
Output is correct |
55 |
Correct |
64 ms |
39232 KB |
Output is correct |
56 |
Correct |
52 ms |
34368 KB |
Output is correct |
57 |
Correct |
54 ms |
34376 KB |
Output is correct |
58 |
Correct |
52 ms |
34876 KB |
Output is correct |
59 |
Correct |
59 ms |
35520 KB |
Output is correct |
60 |
Correct |
54 ms |
36244 KB |
Output is correct |
61 |
Correct |
59 ms |
36156 KB |
Output is correct |
62 |
Correct |
52 ms |
35392 KB |
Output is correct |
63 |
Correct |
65 ms |
36160 KB |
Output is correct |
64 |
Correct |
51 ms |
34112 KB |
Output is correct |
65 |
Correct |
55 ms |
35136 KB |
Output is correct |
66 |
Correct |
46 ms |
34688 KB |
Output is correct |
67 |
Correct |
69 ms |
35316 KB |
Output is correct |
68 |
Correct |
596 ms |
36168 KB |
Output is correct |
69 |
Correct |
776 ms |
36168 KB |
Output is correct |
70 |
Correct |
729 ms |
36160 KB |
Output is correct |
71 |
Correct |
725 ms |
36160 KB |
Output is correct |
72 |
Correct |
783 ms |
36160 KB |
Output is correct |
73 |
Correct |
805 ms |
36160 KB |
Output is correct |
74 |
Correct |
767 ms |
36160 KB |
Output is correct |
75 |
Correct |
678 ms |
34116 KB |
Output is correct |
76 |
Correct |
663 ms |
39232 KB |
Output is correct |
77 |
Correct |
670 ms |
34376 KB |
Output is correct |
78 |
Correct |
725 ms |
39268 KB |
Output is correct |
79 |
Correct |
681 ms |
34368 KB |
Output is correct |
80 |
Correct |
733 ms |
39232 KB |
Output is correct |
81 |
Correct |
15 ms |
26764 KB |
Output is correct |
82 |
Correct |
23 ms |
27004 KB |
Output is correct |
83 |
Correct |
17 ms |
26968 KB |
Output is correct |
84 |
Correct |
57 ms |
36160 KB |
Output is correct |
85 |
Correct |
60 ms |
36160 KB |
Output is correct |
86 |
Correct |
56 ms |
36168 KB |
Output is correct |
87 |
Correct |
57 ms |
39232 KB |
Output is correct |
88 |
Correct |
48 ms |
34188 KB |
Output is correct |
89 |
Correct |
66 ms |
36160 KB |
Output is correct |
90 |
Correct |
53 ms |
36160 KB |
Output is correct |
91 |
Correct |
54 ms |
36164 KB |
Output is correct |
92 |
Correct |
58 ms |
39232 KB |
Output is correct |
93 |
Correct |
48 ms |
34368 KB |
Output is correct |
94 |
Correct |
16 ms |
26968 KB |
Output is correct |
95 |
Correct |
16 ms |
26968 KB |
Output is correct |
96 |
Correct |
17 ms |
26968 KB |
Output is correct |
97 |
Correct |
16 ms |
26968 KB |
Output is correct |
98 |
Correct |
15 ms |
26968 KB |
Output is correct |
99 |
Correct |
17 ms |
26968 KB |
Output is correct |
100 |
Correct |
17 ms |
27048 KB |
Output is correct |
101 |
Correct |
16 ms |
26968 KB |
Output is correct |
102 |
Correct |
16 ms |
26968 KB |
Output is correct |
103 |
Correct |
15 ms |
26968 KB |
Output is correct |
104 |
Correct |
696 ms |
34712 KB |
Output is correct |
105 |
Correct |
781 ms |
35392 KB |
Output is correct |
106 |
Correct |
808 ms |
34624 KB |
Output is correct |
107 |
Correct |
816 ms |
35788 KB |
Output is correct |
108 |
Correct |
772 ms |
34536 KB |
Output is correct |
109 |
Correct |
808 ms |
35392 KB |
Output is correct |
110 |
Correct |
820 ms |
36160 KB |
Output is correct |
111 |
Correct |
717 ms |
34120 KB |
Output is correct |
112 |
Correct |
729 ms |
35392 KB |
Output is correct |
113 |
Correct |
701 ms |
34368 KB |
Output is correct |
114 |
Correct |
701 ms |
35072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
373 ms |
31608 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |