#include "towers.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = int;
const ll big = 1e9+10;
ll n;
vector<ll> h;
//ll mx;
vector<ll> ps;
struct obj{
ll v,c;
bool operator<(const obj &o) const{
return v<o.v;
}
bool operator>(const obj &o) const{
return v>o.v;
}
};
void init(int N, std::vector<int> H) {
n = N;
h = H;
//for(ll i = 0;i<n;i++) if((i==0||(h[i-1]<h[i]))&&(i==n-1||h[i]>h[i+1])) mx = i;
for(ll i = 1;i<n-1;i++){
if (h[i-1]<h[i]&&h[i]>h[i+1]){
ps.push_back(i);
}
}
//for(auto [u,v] : ps) cerr << "[" << u << "," << v << "]" << " ";cerr << "\n";
}
int max_towers(int L, int R, int D) {
ll l = L, r = R, d = D;
ll ans = 1;
auto it0 = lower_bound(ps.begin(),ps.end(),r);
ll rf = it0-ps.begin();
auto it1 = lower_bound(ps.begin(),ps.end(),l+1);
ll lf = it1-ps.begin();
//cerr << lf << " " << rf << "\n";
return max(0,rf-lf)+1;
/*vector<obj> a,b;
a.push_back({0,0});
b.push_back({big,0});
for(ll i = l;i<=r;i++){
ll cur = 0;
auto it = lower_bound(b.begin(),b.end(),obj({h[i]-1,0}),greater<obj>());
--it;
cur = (*it).c;
ans = max(ans,cur+1);
obj oa = {h[i],cur+1};
if (a.size()<=oa.c) a.push_back(oa);
else a[oa.c] = min(a[oa.c],oa);
auto it0 = lower_bound(a.begin(),a.end(),obj({h[i]-d+1,0}));
--it0;
obj ob = {h[i]-d,(*it0).c};
if (b.size()<=ob.c) b.push_back(ob);
else b[ob.c] = max(b[ob.c],ob);
ans = max(ans,cur+1);
//cerr << "a:";for(auto [u,v] : a) cerr << "(" << u <<"," << v << ") ";cerr << "\n";
//cerr << "b:";for(auto [u,v] : b) cerr << "(" << u <<"," << v << ") ";cerr << "\n";
}*/
return ans;
}
Compilation message
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:35:20: warning: unused variable 'd' [-Wunused-variable]
35 | ll l = L, r = R, d = D;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
308 ms |
1112 KB |
2nd 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: '16' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '16' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
525 ms |
1852 KB |
Output is correct |
2 |
Correct |
675 ms |
1880 KB |
Output is correct |
3 |
Correct |
652 ms |
1880 KB |
Output is correct |
4 |
Correct |
682 ms |
1880 KB |
Output is correct |
5 |
Correct |
694 ms |
1880 KB |
Output is correct |
6 |
Correct |
647 ms |
1880 KB |
Output is correct |
7 |
Correct |
652 ms |
1880 KB |
Output is correct |
8 |
Correct |
647 ms |
1600 KB |
Output is correct |
9 |
Correct |
659 ms |
1600 KB |
Output is correct |
10 |
Correct |
627 ms |
1368 KB |
Output is correct |
11 |
Correct |
659 ms |
1368 KB |
Output is correct |
12 |
Correct |
599 ms |
1624 KB |
Output is correct |
13 |
Correct |
643 ms |
1368 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
9 ms |
1956 KB |
Output is correct |
18 |
Correct |
11 ms |
1880 KB |
Output is correct |
19 |
Correct |
9 ms |
1880 KB |
Output is correct |
20 |
Correct |
8 ms |
1600 KB |
Output is correct |
21 |
Correct |
8 ms |
1368 KB |
Output is correct |
22 |
Correct |
10 ms |
1880 KB |
Output is correct |
23 |
Correct |
9 ms |
1880 KB |
Output is correct |
24 |
Correct |
10 ms |
1956 KB |
Output is correct |
25 |
Correct |
8 ms |
1368 KB |
Output is correct |
26 |
Correct |
8 ms |
1600 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
189 ms |
600 KB |
1st lines differ - on the 1st token, expected: '7197', found: '8004' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '16' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
308 ms |
1112 KB |
2nd lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |