# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
754220 |
2023-06-07T09:19:06 Z |
blue |
Radio Towers (IOI22_towers) |
C++17 |
|
1025 ms |
13760 KB |
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
int N;
vi H;
vi LS, RS;
vll dist, dist2;
struct segtree
{
int l;
int r;
int mx = 0;
segtree* left = NULL;
segtree* right = NULL;
segtree()
{
;
}
segtree(int L, int R)
{
l = L;
r = R;
if(l == r)
mx = H[l];
else
{
int m = (l + r)/2;
left = new segtree(l, m);
right = new segtree(m+1, r);
mx = max(left->mx, right->mx);
}
}
int rangemax(int L, int R)
{
if(R < l || r < L)
return -1;
else if(L <= l && r <= R)
return mx;
else
return max(left->rangemax(L, R), right->rangemax(L, R));
}
};
void init(int N_, vi H_)
{
N = N_;
H = H_;
LS = RS = vi(N, -1);
vi st;
st.push_back(-1);
for(int i = 0; i < N; i++)
{
while(st.back() != -1 && H[i] < H[st.back()])
st.pop_back();
LS[i] = st.back();
st.push_back(i);
}
// cerr << "A\n";
segtree ST(0, N-1);
// cerr << "B\n";
st.clear();
st.push_back(N);
for(int i = N-1; i >= 0; i--)
{
while(st.back() != N && H[i] < H[st.back()])
st.pop_back();
RS[i] = st.back();
st.push_back(i);
}
// cerr << "C\n";
for(int i = 0; i < N; i++)
{
dist.push_back(0);
ll lval = 1'000'000'001LL;
if(LS[i] != -1)
lval = ST.rangemax(LS[i]+1, i-1) - H[i];
ll rval = 1'000'000'001LL;
if(RS[i] != N)
rval = ST.rangemax(i+1, RS[i]-1) - H[i];
dist[i] = min(lval, rval);
// cerr << i << " : " << LS[i] << ' ' << RS[i] << ' ' << lval << ' ' << rval << '\n';
}
dist2 = dist;
sort(dist2.begin(), dist2.end());
// cerr << "D\n";
}
int max_towers(int L, int R, int D)
{
// cerr << "enter\n";
int lo = 0, hi = N;
while(lo != hi)
{
int mid = (lo + hi)/2;
if(dist2[mid] < D)
lo = mid+1;
else
hi = mid;
}
// cerr << "exit\n";
return N - lo;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
471 ms |
8352 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
653 ms |
13204 KB |
1st lines differ - on the 1st token, expected: '11903', found: '33010' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
3508 KB |
Output is correct |
2 |
Correct |
699 ms |
13332 KB |
Output is correct |
3 |
Correct |
856 ms |
13344 KB |
Output is correct |
4 |
Correct |
1025 ms |
13340 KB |
Output is correct |
5 |
Correct |
971 ms |
13324 KB |
Output is correct |
6 |
Correct |
884 ms |
13244 KB |
Output is correct |
7 |
Correct |
1008 ms |
13244 KB |
Output is correct |
8 |
Correct |
915 ms |
13760 KB |
Output is correct |
9 |
Correct |
874 ms |
13636 KB |
Output is correct |
10 |
Correct |
968 ms |
13628 KB |
Output is correct |
11 |
Correct |
797 ms |
13628 KB |
Output is correct |
12 |
Correct |
55 ms |
13344 KB |
Output is correct |
13 |
Correct |
51 ms |
13232 KB |
Output is correct |
14 |
Correct |
50 ms |
13292 KB |
Output is correct |
15 |
Correct |
35 ms |
13636 KB |
Output is correct |
16 |
Correct |
47 ms |
13608 KB |
Output is correct |
17 |
Correct |
51 ms |
12900 KB |
Output is correct |
18 |
Correct |
56 ms |
13336 KB |
Output is correct |
19 |
Correct |
68 ms |
13208 KB |
Output is correct |
20 |
Correct |
54 ms |
13332 KB |
Output is correct |
21 |
Correct |
58 ms |
13328 KB |
Output is correct |
22 |
Correct |
64 ms |
13212 KB |
Output is correct |
23 |
Correct |
51 ms |
13324 KB |
Output is correct |
24 |
Correct |
34 ms |
13716 KB |
Output is correct |
25 |
Correct |
32 ms |
13708 KB |
Output is correct |
26 |
Correct |
47 ms |
13540 KB |
Output is correct |
27 |
Correct |
48 ms |
13608 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
2 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
2 ms |
464 KB |
Output is correct |
38 |
Correct |
1 ms |
464 KB |
Output is correct |
39 |
Correct |
1 ms |
464 KB |
Output is correct |
40 |
Correct |
1 ms |
464 KB |
Output is correct |
41 |
Correct |
1 ms |
464 KB |
Output is correct |
42 |
Correct |
1 ms |
464 KB |
Output is correct |
43 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
471 ms |
8352 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |