#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll big = 1000000007;
const int MAXN = 100001;
int n;
vi H2;
struct Segtree {
Segtree *l = 0, *r = 0;
int lo, hi, ma = -big, mi = big, ab = 0, ba = 0;
Segtree(vi& v, int lo, int hi) : lo(lo), hi(hi) {
if (lo + 1 < hi) {
int mid = lo + (hi - lo)/2;
l = new Segtree(v, lo, mid); r = new Segtree(v, mid, hi);
ma = max(l->ma, r->ma);
mi = min(l->mi, r->mi);
ab = max(l->ab, r->ab);
ab = max(ab, (r->ma) - (l->mi));
ba = max(l->ba, r->ba);
ba = max(ba, (l->ma) - (r->mi));
}
else{
ma = v[lo];
mi = v[lo];
}
}
int get_max(int L, int R) {
if (R <= lo || hi <= L) return -big;
if (L <= lo && hi <= R) return ma;
return max(l->get_max(L, R), r->get_max(L, R));
}
int get_min(int L, int R) {
if (R <= lo || hi <= L) return big;
if (L <= lo && hi <= R) return mi;
return min(l->get_min(L, R), r->get_min(L, R));
}
int get_ab(int L, int R){
if (R <= lo || hi <= L) return 0;
if (L <= lo && hi <= R) return ab;
int res = max(l->get_ab(L, R), r->get_ab(L, R));
int x = l->get_min(L,R);
int y = r->get_max(L,R);
return max(res,y-x);
}
int get_ba(int L, int R){
if (R <= lo || hi <= L) return 0;
if (L <= lo && hi <= R) return ba;
int res = max(l->get_ba(L, R), r->get_ba(L, R));
int x = r->get_min(L,R);
int y = l->get_max(L,R);
return max(res,y-x);
}
};
Segtree *ST;
map<int,int> HI;
int delta[MAXN] = {0};
vi ind;
void get_ct(int L, int R){
if(L >= R)return;
if(L == R-1){
delta[L] = 0;
return;
}
int i = HI[ST->get_max(L, R)];
int x = ST->get_min(L,i);
int y = ST->get_min(i+1,R);
delta[i] = H2[i]-max(x, y);
delta[i] = max(delta[i], 0);
get_ct(L, i);
get_ct(i+1,R);
}
bool comp(int i, int j){
return delta[i] > delta[j];
}
void init(int N, vi H){
n = N;
rep(c1,0,n){
H2.push_back(H[c1]);
HI[H[c1]] = c1;
ind.push_back(c1);
}
ST = new Segtree(H2, 0, n);
get_ct(0, n);
sort(all(ind), comp);
}
int max_towers(int L, int R, int D){
int lo = 0;
int hi = n;
if(delta[ind[0]] < D)return 1;
while(lo < hi-1){
int mid = (lo+hi)/2;
if(delta[ind[mid]] < D){
hi = mid;
}
else{
lo = mid;
}
}
return hi + 1;
}
/*
int main() {
int N;
N = 7;
int H[7] = {1,4,2,9,3,6,5};
init(N,H);
cout << max_towers(0, 7, 1) << "\n";
cout << max_towers(0, 7, 2) << "\n";
cout << max_towers(0, 7, 3) << "\n";
cout << max_towers(0, 7, 4) << "\n";
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
488 ms |
14352 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
747 ms |
16136 KB |
1st lines differ - on the 1st token, expected: '11903', found: '33010' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
210 ms |
4144 KB |
Output is correct |
2 |
Correct |
879 ms |
16336 KB |
Output is correct |
3 |
Correct |
894 ms |
16312 KB |
Output is correct |
4 |
Correct |
1006 ms |
16228 KB |
Output is correct |
5 |
Correct |
999 ms |
16276 KB |
Output is correct |
6 |
Correct |
944 ms |
16320 KB |
Output is correct |
7 |
Correct |
893 ms |
16284 KB |
Output is correct |
8 |
Correct |
722 ms |
25640 KB |
Output is correct |
9 |
Correct |
580 ms |
16292 KB |
Output is correct |
10 |
Correct |
953 ms |
21908 KB |
Output is correct |
11 |
Correct |
910 ms |
16328 KB |
Output is correct |
12 |
Correct |
104 ms |
16308 KB |
Output is correct |
13 |
Correct |
97 ms |
16252 KB |
Output is correct |
14 |
Correct |
107 ms |
16468 KB |
Output is correct |
15 |
Correct |
84 ms |
16276 KB |
Output is correct |
16 |
Correct |
85 ms |
24868 KB |
Output is correct |
17 |
Correct |
96 ms |
15800 KB |
Output is correct |
18 |
Correct |
105 ms |
16236 KB |
Output is correct |
19 |
Correct |
133 ms |
16344 KB |
Output is correct |
20 |
Correct |
112 ms |
16272 KB |
Output is correct |
21 |
Correct |
97 ms |
16268 KB |
Output is correct |
22 |
Correct |
94 ms |
16344 KB |
Output is correct |
23 |
Correct |
95 ms |
16232 KB |
Output is correct |
24 |
Correct |
85 ms |
25704 KB |
Output is correct |
25 |
Correct |
89 ms |
16296 KB |
Output is correct |
26 |
Correct |
84 ms |
21944 KB |
Output is correct |
27 |
Correct |
83 ms |
16284 KB |
Output is correct |
28 |
Correct |
2 ms |
592 KB |
Output is correct |
29 |
Correct |
1 ms |
592 KB |
Output is correct |
30 |
Correct |
2 ms |
592 KB |
Output is correct |
31 |
Correct |
1 ms |
592 KB |
Output is correct |
32 |
Correct |
2 ms |
720 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
2 ms |
592 KB |
Output is correct |
35 |
Correct |
2 ms |
592 KB |
Output is correct |
36 |
Correct |
2 ms |
592 KB |
Output is correct |
37 |
Correct |
1 ms |
592 KB |
Output is correct |
38 |
Correct |
1 ms |
592 KB |
Output is correct |
39 |
Correct |
2 ms |
592 KB |
Output is correct |
40 |
Correct |
2 ms |
720 KB |
Output is correct |
41 |
Correct |
2 ms |
592 KB |
Output is correct |
42 |
Correct |
2 ms |
720 KB |
Output is correct |
43 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
488 ms |
14352 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |