#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 100005;
int n, d;
int a[N];
int ul[N], ur[N];
vector<pair<pair<int, int>, pair<int, int> > > b;
int z;
int s[N * 18 * 18];
int sl[N * 18 * 18], sr[N * 18 * 18];
void ubdy(int tl, int tr, int l, int r, int posy)
{
if (l > r)
return;
if (tl == l && tr == r)
{
s[posy]++;
return;
}
int m = (tl + tr) / 2;
if (sl[posy] == 0)
sl[posy] = ++z;
if (sr[posy] == 0)
sr[posy] = ++z;
ubdy(tl, m, l, min(m, r), sl[posy]);
ubdy(m + 1, tr, max(m + 1, l), r, sr[posy]);
}
int r[N * 4];
void ubdx(int tl, int tr, int lx, int rx, int ly, int ry, int posx)
{
if (lx > rx)
return;
if (tl == lx && tr == rx)
{
if (r[posx] == 0)
r[posx] = ++z;
ubdy(1, n, ly, ry, r[posx]);
return;
}
int m = (tl + tr) / 2;
ubdx(tl, m, lx, min(m, rx), ly, ry, posx * 2);
ubdx(m + 1, tr, max(m + 1, lx), rx, ly, ry, posx * 2 + 1);
}
int qryy(int tl, int tr, int y, int posy)
{
if (posy == 0)
return 0;
if (tl == tr)
return s[posy];
int m = (tl + tr) / 2;
if (y <= m)
return qryy(tl, m, y, sl[posy]) + s[posy];
return qryy(m + 1, tr, y, sr[posy]) + s[posy];
}
int qryx(int tl, int tr, int x, int y, int posx)
{
if (tl == tr)
return qryy(1, n, y, r[posx]);
int m = (tl + tr) / 2;
if (x <= m)
return qryx(tl, m, x, y, posx * 2) + qryy(1, n, y, r[posx]);
return qryx(m + 1, tr, x, y, posx * 2 + 1) + qryy(1, n, y, r[posx]);
}
void pre()
{
b.clear();
vector<int> s;
for (int i = 1; i <= n; ++i)
{
while (!s.empty() && a[s.back()] <= a[i])
s.pop_back();
s.push_back(i);
int l = 0, r = sz(s) - 1;
ul[i] = 0;
while (l <= r)
{
int m = (l + r) / 2;
if (a[s[m]] - d >= a[i])
{
ul[i] = s[m];
l = m + 1;
}
else
{
r = m - 1;
}
}
}
s.clear();
for (int i = n; i >= 1; --i)
{
while (!s.empty() && a[s.back()] <= a[i])
s.pop_back();
s.push_back(i);
int l = 0, r = sz(s) - 1;
ur[i] = n + 1;
while (l <= r)
{
int m = (l + r) / 2;
if (a[s[m]] - d >= a[i])
{
ur[i] = s[m];
l = m + 1;
}
else
r = m - 1;
}
}
for (int i = 1; i <= n; ++i)
{
ul[i]++;
ur[i]--;
}
for (int i = 1; i <= n; ++i)
{
b.push_back(m_p(m_p(ur[i] - ul[i] + 1, i), m_p(ul[i], ur[i])));
}
sort(all(b));
set<int> t;
t.insert(0);
t.insert(n + 1);
for (int ii = 0; ii < n; ++ii)
{
int i = b[ii].fi.se;
t.insert(i);
auto it = t.find(i);
--it;
if (ur[*it] < ul[i])
b[ii].fi.fi = 1;
else
b[ii].fi.fi = *it + 1;
b[ii].fi.se = i;
++it;
++it;
b[ii].se.fi = i;
if (ur[i] < ul[*it])
b[ii].se.se = n;
else
b[ii].se.se = *it - 1;
}
for (int i = 0; i < n; ++i)
{
ubdx(1, n, b[i].fi.fi, b[i].fi.se, b[i].se.fi, b[i].se.se, 1);
}
}
void init(int N, std::vector<int> H)
{
n = N;
for (int i = 1; i <= n; ++i)
a[i] = H[i - 1];
}
int max_towers(int L, int R, int D)
{
++L;
++R;
if (b.empty())
{
d = D;
pre();
}
return qryx(1, n, L, R, 1);
}
/*
7 1
10 20 60 40 50 30 70
0 1 17
7 3
10 20 60 40 50 30 70
1 5 10
2 2 100
0 6 17
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
378 ms |
33792 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
2 ms |
1232 KB |
Output is correct |
3 |
Correct |
2 ms |
1104 KB |
Output is correct |
4 |
Correct |
2 ms |
1232 KB |
Output is correct |
5 |
Correct |
3 ms |
1232 KB |
Output is correct |
6 |
Correct |
2 ms |
1232 KB |
Output is correct |
7 |
Correct |
2 ms |
1168 KB |
Output is correct |
8 |
Correct |
2 ms |
976 KB |
Output is correct |
9 |
Correct |
2 ms |
1232 KB |
Output is correct |
10 |
Correct |
1 ms |
976 KB |
Output is correct |
11 |
Correct |
2 ms |
1232 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
1232 KB |
Output is correct |
14 |
Correct |
2 ms |
1232 KB |
Output is correct |
15 |
Correct |
3 ms |
1200 KB |
Output is correct |
16 |
Correct |
3 ms |
1232 KB |
Output is correct |
17 |
Correct |
2 ms |
1232 KB |
Output is correct |
18 |
Correct |
2 ms |
1232 KB |
Output is correct |
19 |
Correct |
2 ms |
976 KB |
Output is correct |
20 |
Correct |
2 ms |
1232 KB |
Output is correct |
21 |
Correct |
2 ms |
1232 KB |
Output is correct |
22 |
Correct |
2 ms |
1232 KB |
Output is correct |
23 |
Correct |
2 ms |
1232 KB |
Output is correct |
24 |
Correct |
1 ms |
976 KB |
Output is correct |
25 |
Correct |
1 ms |
592 KB |
Output is correct |
26 |
Correct |
2 ms |
1104 KB |
Output is correct |
27 |
Correct |
2 ms |
1232 KB |
Output is correct |
28 |
Correct |
2 ms |
1232 KB |
Output is correct |
29 |
Correct |
2 ms |
1232 KB |
Output is correct |
30 |
Correct |
2 ms |
1232 KB |
Output is correct |
31 |
Correct |
2 ms |
1232 KB |
Output is correct |
32 |
Correct |
2 ms |
976 KB |
Output is correct |
33 |
Correct |
2 ms |
1232 KB |
Output is correct |
34 |
Correct |
1 ms |
976 KB |
Output is correct |
35 |
Correct |
2 ms |
1232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
2 ms |
1232 KB |
Output is correct |
3 |
Correct |
2 ms |
1104 KB |
Output is correct |
4 |
Correct |
2 ms |
1232 KB |
Output is correct |
5 |
Correct |
3 ms |
1232 KB |
Output is correct |
6 |
Correct |
2 ms |
1232 KB |
Output is correct |
7 |
Correct |
2 ms |
1168 KB |
Output is correct |
8 |
Correct |
2 ms |
976 KB |
Output is correct |
9 |
Correct |
2 ms |
1232 KB |
Output is correct |
10 |
Correct |
1 ms |
976 KB |
Output is correct |
11 |
Correct |
2 ms |
1232 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
1232 KB |
Output is correct |
14 |
Correct |
2 ms |
1232 KB |
Output is correct |
15 |
Correct |
3 ms |
1200 KB |
Output is correct |
16 |
Correct |
3 ms |
1232 KB |
Output is correct |
17 |
Correct |
2 ms |
1232 KB |
Output is correct |
18 |
Correct |
2 ms |
1232 KB |
Output is correct |
19 |
Correct |
2 ms |
976 KB |
Output is correct |
20 |
Correct |
2 ms |
1232 KB |
Output is correct |
21 |
Correct |
2 ms |
1232 KB |
Output is correct |
22 |
Correct |
2 ms |
1232 KB |
Output is correct |
23 |
Correct |
2 ms |
1232 KB |
Output is correct |
24 |
Correct |
1 ms |
976 KB |
Output is correct |
25 |
Correct |
1 ms |
592 KB |
Output is correct |
26 |
Correct |
2 ms |
1104 KB |
Output is correct |
27 |
Correct |
2 ms |
1232 KB |
Output is correct |
28 |
Correct |
2 ms |
1232 KB |
Output is correct |
29 |
Correct |
2 ms |
1232 KB |
Output is correct |
30 |
Correct |
2 ms |
1232 KB |
Output is correct |
31 |
Correct |
2 ms |
1232 KB |
Output is correct |
32 |
Correct |
2 ms |
976 KB |
Output is correct |
33 |
Correct |
2 ms |
1232 KB |
Output is correct |
34 |
Correct |
1 ms |
976 KB |
Output is correct |
35 |
Correct |
2 ms |
1232 KB |
Output is correct |
36 |
Correct |
85 ms |
41988 KB |
Output is correct |
37 |
Correct |
108 ms |
62600 KB |
Output is correct |
38 |
Correct |
147 ms |
64884 KB |
Output is correct |
39 |
Correct |
97 ms |
61236 KB |
Output is correct |
40 |
Correct |
135 ms |
67076 KB |
Output is correct |
41 |
Correct |
129 ms |
65468 KB |
Output is correct |
42 |
Correct |
134 ms |
67544 KB |
Output is correct |
43 |
Correct |
86 ms |
47220 KB |
Output is correct |
44 |
Correct |
120 ms |
70776 KB |
Output is correct |
45 |
Correct |
86 ms |
47100 KB |
Output is correct |
46 |
Correct |
123 ms |
74300 KB |
Output is correct |
47 |
Correct |
145 ms |
66460 KB |
Output is correct |
48 |
Correct |
132 ms |
67576 KB |
Output is correct |
49 |
Correct |
127 ms |
67632 KB |
Output is correct |
50 |
Correct |
153 ms |
66716 KB |
Output is correct |
51 |
Correct |
89 ms |
47272 KB |
Output is correct |
52 |
Correct |
144 ms |
66360 KB |
Output is correct |
53 |
Correct |
133 ms |
67640 KB |
Output is correct |
54 |
Correct |
129 ms |
67572 KB |
Output is correct |
55 |
Correct |
153 ms |
66708 KB |
Output is correct |
56 |
Correct |
82 ms |
47220 KB |
Output is correct |
57 |
Correct |
114 ms |
60964 KB |
Output is correct |
58 |
Correct |
123 ms |
64280 KB |
Output is correct |
59 |
Correct |
141 ms |
65380 KB |
Output is correct |
60 |
Correct |
142 ms |
67564 KB |
Output is correct |
61 |
Correct |
158 ms |
67092 KB |
Output is correct |
62 |
Correct |
134 ms |
66068 KB |
Output is correct |
63 |
Correct |
136 ms |
67180 KB |
Output is correct |
64 |
Correct |
84 ms |
47268 KB |
Output is correct |
65 |
Correct |
123 ms |
77608 KB |
Output is correct |
66 |
Correct |
94 ms |
59328 KB |
Output is correct |
67 |
Correct |
127 ms |
75044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
710 ms |
65928 KB |
Output is correct |
2 |
Correct |
869 ms |
66288 KB |
Output is correct |
3 |
Correct |
850 ms |
66468 KB |
Output is correct |
4 |
Correct |
943 ms |
67636 KB |
Output is correct |
5 |
Correct |
1008 ms |
67636 KB |
Output is correct |
6 |
Correct |
861 ms |
67556 KB |
Output is correct |
7 |
Correct |
896 ms |
67620 KB |
Output is correct |
8 |
Correct |
732 ms |
47316 KB |
Output is correct |
9 |
Correct |
886 ms |
66812 KB |
Output is correct |
10 |
Correct |
731 ms |
47216 KB |
Output is correct |
11 |
Correct |
900 ms |
66532 KB |
Output is correct |
12 |
Correct |
821 ms |
47472 KB |
Output is correct |
13 |
Correct |
1140 ms |
66636 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
1128 KB |
Output is correct |
16 |
Correct |
2 ms |
1232 KB |
Output is correct |
17 |
Correct |
143 ms |
66436 KB |
Output is correct |
18 |
Correct |
141 ms |
67540 KB |
Output is correct |
19 |
Correct |
132 ms |
67592 KB |
Output is correct |
20 |
Correct |
162 ms |
66696 KB |
Output is correct |
21 |
Correct |
83 ms |
47256 KB |
Output is correct |
22 |
Correct |
146 ms |
66404 KB |
Output is correct |
23 |
Correct |
128 ms |
67608 KB |
Output is correct |
24 |
Correct |
136 ms |
67612 KB |
Output is correct |
25 |
Correct |
152 ms |
66724 KB |
Output is correct |
26 |
Correct |
83 ms |
47216 KB |
Output is correct |
27 |
Correct |
2 ms |
1232 KB |
Output is correct |
28 |
Correct |
2 ms |
1232 KB |
Output is correct |
29 |
Correct |
2 ms |
1232 KB |
Output is correct |
30 |
Correct |
2 ms |
1232 KB |
Output is correct |
31 |
Correct |
2 ms |
976 KB |
Output is correct |
32 |
Correct |
2 ms |
1232 KB |
Output is correct |
33 |
Correct |
3 ms |
1232 KB |
Output is correct |
34 |
Correct |
2 ms |
1232 KB |
Output is correct |
35 |
Correct |
2 ms |
1232 KB |
Output is correct |
36 |
Correct |
1 ms |
976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
292 ms |
14152 KB |
2nd lines differ - on the 1st token, expected: '7063', found: '7197' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
2 ms |
1232 KB |
Output is correct |
3 |
Correct |
2 ms |
1104 KB |
Output is correct |
4 |
Correct |
2 ms |
1232 KB |
Output is correct |
5 |
Correct |
3 ms |
1232 KB |
Output is correct |
6 |
Correct |
2 ms |
1232 KB |
Output is correct |
7 |
Correct |
2 ms |
1168 KB |
Output is correct |
8 |
Correct |
2 ms |
976 KB |
Output is correct |
9 |
Correct |
2 ms |
1232 KB |
Output is correct |
10 |
Correct |
1 ms |
976 KB |
Output is correct |
11 |
Correct |
2 ms |
1232 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
1232 KB |
Output is correct |
14 |
Correct |
2 ms |
1232 KB |
Output is correct |
15 |
Correct |
3 ms |
1200 KB |
Output is correct |
16 |
Correct |
3 ms |
1232 KB |
Output is correct |
17 |
Correct |
2 ms |
1232 KB |
Output is correct |
18 |
Correct |
2 ms |
1232 KB |
Output is correct |
19 |
Correct |
2 ms |
976 KB |
Output is correct |
20 |
Correct |
2 ms |
1232 KB |
Output is correct |
21 |
Correct |
2 ms |
1232 KB |
Output is correct |
22 |
Correct |
2 ms |
1232 KB |
Output is correct |
23 |
Correct |
2 ms |
1232 KB |
Output is correct |
24 |
Correct |
1 ms |
976 KB |
Output is correct |
25 |
Correct |
1 ms |
592 KB |
Output is correct |
26 |
Correct |
2 ms |
1104 KB |
Output is correct |
27 |
Correct |
2 ms |
1232 KB |
Output is correct |
28 |
Correct |
2 ms |
1232 KB |
Output is correct |
29 |
Correct |
2 ms |
1232 KB |
Output is correct |
30 |
Correct |
2 ms |
1232 KB |
Output is correct |
31 |
Correct |
2 ms |
1232 KB |
Output is correct |
32 |
Correct |
2 ms |
976 KB |
Output is correct |
33 |
Correct |
2 ms |
1232 KB |
Output is correct |
34 |
Correct |
1 ms |
976 KB |
Output is correct |
35 |
Correct |
2 ms |
1232 KB |
Output is correct |
36 |
Correct |
85 ms |
41988 KB |
Output is correct |
37 |
Correct |
108 ms |
62600 KB |
Output is correct |
38 |
Correct |
147 ms |
64884 KB |
Output is correct |
39 |
Correct |
97 ms |
61236 KB |
Output is correct |
40 |
Correct |
135 ms |
67076 KB |
Output is correct |
41 |
Correct |
129 ms |
65468 KB |
Output is correct |
42 |
Correct |
134 ms |
67544 KB |
Output is correct |
43 |
Correct |
86 ms |
47220 KB |
Output is correct |
44 |
Correct |
120 ms |
70776 KB |
Output is correct |
45 |
Correct |
86 ms |
47100 KB |
Output is correct |
46 |
Correct |
123 ms |
74300 KB |
Output is correct |
47 |
Correct |
145 ms |
66460 KB |
Output is correct |
48 |
Correct |
132 ms |
67576 KB |
Output is correct |
49 |
Correct |
127 ms |
67632 KB |
Output is correct |
50 |
Correct |
153 ms |
66716 KB |
Output is correct |
51 |
Correct |
89 ms |
47272 KB |
Output is correct |
52 |
Correct |
144 ms |
66360 KB |
Output is correct |
53 |
Correct |
133 ms |
67640 KB |
Output is correct |
54 |
Correct |
129 ms |
67572 KB |
Output is correct |
55 |
Correct |
153 ms |
66708 KB |
Output is correct |
56 |
Correct |
82 ms |
47220 KB |
Output is correct |
57 |
Correct |
114 ms |
60964 KB |
Output is correct |
58 |
Correct |
123 ms |
64280 KB |
Output is correct |
59 |
Correct |
141 ms |
65380 KB |
Output is correct |
60 |
Correct |
142 ms |
67564 KB |
Output is correct |
61 |
Correct |
158 ms |
67092 KB |
Output is correct |
62 |
Correct |
134 ms |
66068 KB |
Output is correct |
63 |
Correct |
136 ms |
67180 KB |
Output is correct |
64 |
Correct |
84 ms |
47268 KB |
Output is correct |
65 |
Correct |
123 ms |
77608 KB |
Output is correct |
66 |
Correct |
94 ms |
59328 KB |
Output is correct |
67 |
Correct |
127 ms |
75044 KB |
Output is correct |
68 |
Correct |
710 ms |
65928 KB |
Output is correct |
69 |
Correct |
869 ms |
66288 KB |
Output is correct |
70 |
Correct |
850 ms |
66468 KB |
Output is correct |
71 |
Correct |
943 ms |
67636 KB |
Output is correct |
72 |
Correct |
1008 ms |
67636 KB |
Output is correct |
73 |
Correct |
861 ms |
67556 KB |
Output is correct |
74 |
Correct |
896 ms |
67620 KB |
Output is correct |
75 |
Correct |
732 ms |
47316 KB |
Output is correct |
76 |
Correct |
886 ms |
66812 KB |
Output is correct |
77 |
Correct |
731 ms |
47216 KB |
Output is correct |
78 |
Correct |
900 ms |
66532 KB |
Output is correct |
79 |
Correct |
821 ms |
47472 KB |
Output is correct |
80 |
Correct |
1140 ms |
66636 KB |
Output is correct |
81 |
Correct |
1 ms |
336 KB |
Output is correct |
82 |
Correct |
2 ms |
1128 KB |
Output is correct |
83 |
Correct |
2 ms |
1232 KB |
Output is correct |
84 |
Correct |
143 ms |
66436 KB |
Output is correct |
85 |
Correct |
141 ms |
67540 KB |
Output is correct |
86 |
Correct |
132 ms |
67592 KB |
Output is correct |
87 |
Correct |
162 ms |
66696 KB |
Output is correct |
88 |
Correct |
83 ms |
47256 KB |
Output is correct |
89 |
Correct |
146 ms |
66404 KB |
Output is correct |
90 |
Correct |
128 ms |
67608 KB |
Output is correct |
91 |
Correct |
136 ms |
67612 KB |
Output is correct |
92 |
Correct |
152 ms |
66724 KB |
Output is correct |
93 |
Correct |
83 ms |
47216 KB |
Output is correct |
94 |
Correct |
2 ms |
1232 KB |
Output is correct |
95 |
Correct |
2 ms |
1232 KB |
Output is correct |
96 |
Correct |
2 ms |
1232 KB |
Output is correct |
97 |
Correct |
2 ms |
1232 KB |
Output is correct |
98 |
Correct |
2 ms |
976 KB |
Output is correct |
99 |
Correct |
2 ms |
1232 KB |
Output is correct |
100 |
Correct |
3 ms |
1232 KB |
Output is correct |
101 |
Correct |
2 ms |
1232 KB |
Output is correct |
102 |
Correct |
2 ms |
1232 KB |
Output is correct |
103 |
Correct |
1 ms |
976 KB |
Output is correct |
104 |
Correct |
806 ms |
58004 KB |
Output is correct |
105 |
Correct |
799 ms |
65248 KB |
Output is correct |
106 |
Correct |
920 ms |
63536 KB |
Output is correct |
107 |
Correct |
915 ms |
66220 KB |
Output is correct |
108 |
Correct |
856 ms |
61740 KB |
Output is correct |
109 |
Correct |
931 ms |
66020 KB |
Output is correct |
110 |
Correct |
942 ms |
67624 KB |
Output is correct |
111 |
Correct |
901 ms |
47292 KB |
Output is correct |
112 |
Correct |
929 ms |
77348 KB |
Output is correct |
113 |
Correct |
749 ms |
71332 KB |
Output is correct |
114 |
Correct |
768 ms |
71036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
378 ms |
33792 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |