// Om Namah Shivaya
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define conts continue
#define sz(a) a.size()
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &x, T y){
x = min(x,y);
}
template<typename T>
void amax(T &x, T y){
x = max(x,y);
}
#define debug(x) cout << #x << " = "; cout << x; cout << endl
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = 1e9 + 5;
const ll inf2 = (ll)1e18 + 5;
#include "towers.h"
template<typename T>
struct segtree{
struct data{
int a;
};
data d_neutral = {-inf1};
data merge(data &left, data &right){
data curr;
curr.a = max(left.a,right.a);
return curr;
}
void modify(int i, T v){
tr[i].a = v;
}
int n;
vector<data> tr;
segtree(int n_){
n = n_;
tr.assign(2*n+5,d_neutral);
}
void pupd(int i, T v){
modify(i+n,v);
for(i = (i+n)>>1; i; i >>= 1){
tr[i] = merge(tr[i<<1],tr[i<<1|1]);
}
}
data query(int l, int r){
data res = d_neutral;
for(l += n, r += n; l <= r; l >>= 1, r >>= 1){
if(l & 1){
res = merge(res,tr[l++]);
}
if(!(r & 1)){
res = merge(res,tr[r--]);
}
}
return res;
}
};
int n;
vector<int> a;
void init(int n_, std::vector<int> a_) {
n = n_;
a = a_;
}
int max_towers(int L, int R, int D) {
vector<int> b;
for(int i = L; i <= R; ++i){
b.pb(a[i]);
}
int m = sz(b);
segtree<int> st(m+5);
rep(i,m) st.pupd(i,b[i]);
vector<int> lx(m,-1), rx(m,inf1);
rep(i,m){
int lo = 0, hi = i-1;
while(lo <= hi){
int mid = (lo+hi) >> 1;
int mx = st.query(mid,i-1).a;
if(b[i] <= mx-D){
lx[i] = mid-1;
lo = mid+1;
}
else{
hi = mid-1;
}
}
lo = i+1, hi = m-1;
while(lo <= hi){
int mid = (lo+hi) >> 1;
int mx = st.query(i+1,mid).a;
if(b[i] <= mx-D){
rx[i] = mid+1;
hi = mid-1;
}
else{
lo = mid+1;
}
}
}
vector<int> here[m];
rep(i,m){
if(rx[i] < m){
here[rx[i]].pb(i);
}
}
vector<int> dp(m);
st = segtree<int>(m+5);
rep(i,m){
dp[i] = 1;
trav(j,here[i]){
st.pupd(j,dp[j]);
}
int mx = st.query(0,lx[i]).a;
amax(dp[i],mx+1);
}
int ans = *max_element(all(dp));
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4042 ms |
4548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
288 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
448 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
3 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
3 ms |
336 KB |
Output is correct |
32 |
Correct |
3 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
436 KB |
Output is correct |
34 |
Correct |
3 ms |
336 KB |
Output is correct |
35 |
Correct |
3 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
288 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
448 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
3 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
3 ms |
336 KB |
Output is correct |
32 |
Correct |
3 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
436 KB |
Output is correct |
34 |
Correct |
3 ms |
336 KB |
Output is correct |
35 |
Correct |
3 ms |
336 KB |
Output is correct |
36 |
Correct |
32 ms |
1992 KB |
Output is correct |
37 |
Correct |
77 ms |
3048 KB |
Output is correct |
38 |
Correct |
29 ms |
1856 KB |
Output is correct |
39 |
Correct |
68 ms |
2852 KB |
Output is correct |
40 |
Correct |
31 ms |
1836 KB |
Output is correct |
41 |
Correct |
167 ms |
6284 KB |
Output is correct |
42 |
Correct |
10 ms |
1360 KB |
Output is correct |
43 |
Correct |
119 ms |
4364 KB |
Output is correct |
44 |
Correct |
36 ms |
1808 KB |
Output is correct |
45 |
Correct |
12 ms |
1444 KB |
Output is correct |
46 |
Correct |
10 ms |
1452 KB |
Output is correct |
47 |
Correct |
56 ms |
3548 KB |
Output is correct |
48 |
Correct |
34 ms |
2556 KB |
Output is correct |
49 |
Correct |
22 ms |
1580 KB |
Output is correct |
50 |
Correct |
41 ms |
2192 KB |
Output is correct |
51 |
Correct |
75 ms |
4380 KB |
Output is correct |
52 |
Correct |
168 ms |
8176 KB |
Output is correct |
53 |
Correct |
167 ms |
8156 KB |
Output is correct |
54 |
Correct |
171 ms |
8172 KB |
Output is correct |
55 |
Correct |
204 ms |
6480 KB |
Output is correct |
56 |
Correct |
197 ms |
9688 KB |
Output is correct |
57 |
Correct |
210 ms |
6788 KB |
Output is correct |
58 |
Correct |
210 ms |
7256 KB |
Output is correct |
59 |
Correct |
194 ms |
7636 KB |
Output is correct |
60 |
Correct |
168 ms |
8156 KB |
Output is correct |
61 |
Correct |
189 ms |
7976 KB |
Output is correct |
62 |
Correct |
199 ms |
7636 KB |
Output is correct |
63 |
Correct |
188 ms |
8000 KB |
Output is correct |
64 |
Correct |
238 ms |
7260 KB |
Output is correct |
65 |
Correct |
239 ms |
6492 KB |
Output is correct |
66 |
Correct |
243 ms |
7384 KB |
Output is correct |
67 |
Correct |
238 ms |
6604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4027 ms |
7524 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4027 ms |
2380 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
288 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
448 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
3 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
3 ms |
336 KB |
Output is correct |
32 |
Correct |
3 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
436 KB |
Output is correct |
34 |
Correct |
3 ms |
336 KB |
Output is correct |
35 |
Correct |
3 ms |
336 KB |
Output is correct |
36 |
Correct |
32 ms |
1992 KB |
Output is correct |
37 |
Correct |
77 ms |
3048 KB |
Output is correct |
38 |
Correct |
29 ms |
1856 KB |
Output is correct |
39 |
Correct |
68 ms |
2852 KB |
Output is correct |
40 |
Correct |
31 ms |
1836 KB |
Output is correct |
41 |
Correct |
167 ms |
6284 KB |
Output is correct |
42 |
Correct |
10 ms |
1360 KB |
Output is correct |
43 |
Correct |
119 ms |
4364 KB |
Output is correct |
44 |
Correct |
36 ms |
1808 KB |
Output is correct |
45 |
Correct |
12 ms |
1444 KB |
Output is correct |
46 |
Correct |
10 ms |
1452 KB |
Output is correct |
47 |
Correct |
56 ms |
3548 KB |
Output is correct |
48 |
Correct |
34 ms |
2556 KB |
Output is correct |
49 |
Correct |
22 ms |
1580 KB |
Output is correct |
50 |
Correct |
41 ms |
2192 KB |
Output is correct |
51 |
Correct |
75 ms |
4380 KB |
Output is correct |
52 |
Correct |
168 ms |
8176 KB |
Output is correct |
53 |
Correct |
167 ms |
8156 KB |
Output is correct |
54 |
Correct |
171 ms |
8172 KB |
Output is correct |
55 |
Correct |
204 ms |
6480 KB |
Output is correct |
56 |
Correct |
197 ms |
9688 KB |
Output is correct |
57 |
Correct |
210 ms |
6788 KB |
Output is correct |
58 |
Correct |
210 ms |
7256 KB |
Output is correct |
59 |
Correct |
194 ms |
7636 KB |
Output is correct |
60 |
Correct |
168 ms |
8156 KB |
Output is correct |
61 |
Correct |
189 ms |
7976 KB |
Output is correct |
62 |
Correct |
199 ms |
7636 KB |
Output is correct |
63 |
Correct |
188 ms |
8000 KB |
Output is correct |
64 |
Correct |
238 ms |
7260 KB |
Output is correct |
65 |
Correct |
239 ms |
6492 KB |
Output is correct |
66 |
Correct |
243 ms |
7384 KB |
Output is correct |
67 |
Correct |
238 ms |
6604 KB |
Output is correct |
68 |
Execution timed out |
4027 ms |
7524 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4042 ms |
4548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |