#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
//#define ll long long
//#define int long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 1000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define YES cout <<"YES\n"
#define NO cout << "NO\n"
#define debug cout << "Here Fine" << endl ;
#define pr pair < int , int >
#define fbo find_by_order // returns iterator
#define ook order_of_key // returns strictly less numbers than key
using namespace std ;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const double Pi=acos(-1.0);
const double EPS=1E-8;
const int mod = 1000000007 ;
const int mod1 = 998244353 ;
const int N = 4e5 + 10 ;
//mt19937 R(time(0));
map < string , int > ma , ma1 ;
#include "towers.h"
int n , a[ N ] ;
pair < int , int > node[ 4 * N ] ;
void build( int v , int vl , int vr ){
if( vl == vr ){
node[ v ] = { a[ vl - 1 ] , vl - 1 } ;
return ;
}
int vm= ( vl + vr ) / 2 ;
build( v + v , vl , vm ) ;
build( v + v + 1 , vm + 1 , vr ) ;
node[ v ] = max( node[ v + v ] , node[ v + v + 1 ] ) ;
return ;
}
pair < int , int > get( int v , int vl , int vr , int l , int r ){
if( l > r ) return { 0 , 0 } ;
if( vl == l && vr == r ) return node[ v ] ;
int vm = ( vl + vr ) / 2 ;
pair < int , int > a , b ;
a = get( v + v , vl , vm, l , min( r , vm ) ) ;
b = get( v + v + 1 , vm + 1 , vr , max( vm + 1 , l ) , r ) ;
return max( a , b ) ;
}
void init(int N, std::vector<int> H){
n = N ; FOR( i , N ) a[ i ] = H[ i ] ;
// if this works make it into segment tree ?
build( 1 , 1 , n ) ;
return ;
}
map < pair < int , pair < int , int > > , int > dp ;
int get( int l , int r , int mx , int d ){
pair < int , pair < int , int > > axla ;
axla.f = l ; axla.s.f = r ; axla.s.s = mx ;
if( dp.find( axla ) != dp.end() ) return dp[ axla ] ;
if( l > r ) return 0 ;
if( l == r && a[ l ] <= mx ) return 1 ;
if( l == r ) return 0 ;
pair < int , int > p ;
p = get( 1 , 1 , n , l + 1 , r + 1 ) ;
int cur_max = p.f ;
int cur_pos = p.s ;
int pas = 0 ;
// now case work
if( cur_max <= mx ) pas = 1 ;
int A , B ;
// first both sides
A = get( l , cur_pos - 1 , cur_max - d , d ) ;
B = get( cur_pos + 1 , r , cur_max - d , d ) ;
pas = max( pas , A + B ) ;
// only left side
A = get( l , cur_pos - 1 , mx , d ) ;
pas = max( pas , A ) ;
// only right
B = get( cur_pos + 1 , r , mx , d ) ;
pas = max( pas , B ) ;
// Done? Hopefully
dp[ axla ] = pas ;
return pas ;
}
int max_towers(int L, int R, int D){
pair < int , int > p ;
p = get( 1 , 1 , n , L + 1 , R + 1 ) ;
int mx = p.f ;
int pos = p.s ;
return max( 1 , ( get( L , pos - 1 , mx , D ) + get( pos + 1 , R , mx - D , D ) ) ) ;
}
// int main() {
// int N, Q;
// assert(2 == scanf("%d %d", &N, &Q));
// std::vector<int> H(N);
// for (int i = 0; i < N; ++i) {
// assert(1 == scanf("%d", &H[i]));
// }
// init(N, H);
// for (int i = 0; i < Q; ++i) {
// int L, R, D;
// assert(3 == scanf("%d %d %d", &L, &R, &D));
// printf("%d\n", max_towers(L, R, D));
// }
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4062 ms |
225600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
720 KB |
Output is correct |
3 |
Correct |
4 ms |
652 KB |
Output is correct |
4 |
Correct |
3 ms |
592 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
20 ms |
1952 KB |
Output is correct |
9 |
Correct |
75 ms |
6784 KB |
Output is correct |
10 |
Correct |
11 ms |
1308 KB |
Output is correct |
11 |
Correct |
57 ms |
5252 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
384 ms |
23312 KB |
Output is correct |
14 |
Correct |
211 ms |
14324 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
4 ms |
720 KB |
Output is correct |
17 |
Correct |
2 ms |
464 KB |
Output is correct |
18 |
Correct |
43 ms |
4380 KB |
Output is correct |
19 |
Correct |
96 ms |
10088 KB |
Output is correct |
20 |
Correct |
9 ms |
1296 KB |
Output is correct |
21 |
Correct |
6 ms |
976 KB |
Output is correct |
22 |
Correct |
7 ms |
976 KB |
Output is correct |
23 |
Correct |
2948 ms |
125696 KB |
Output is correct |
24 |
Correct |
1848 ms |
104080 KB |
Output is correct |
25 |
Correct |
5 ms |
720 KB |
Output is correct |
26 |
Correct |
10 ms |
1232 KB |
Output is correct |
27 |
Correct |
10 ms |
1296 KB |
Output is correct |
28 |
Correct |
7 ms |
976 KB |
Output is correct |
29 |
Correct |
9 ms |
1060 KB |
Output is correct |
30 |
Correct |
8 ms |
1104 KB |
Output is correct |
31 |
Correct |
6 ms |
976 KB |
Output is correct |
32 |
Correct |
2486 ms |
125588 KB |
Output is correct |
33 |
Correct |
3002 ms |
125508 KB |
Output is correct |
34 |
Correct |
1849 ms |
110904 KB |
Output is correct |
35 |
Correct |
3195 ms |
117112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
720 KB |
Output is correct |
3 |
Correct |
4 ms |
652 KB |
Output is correct |
4 |
Correct |
3 ms |
592 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
20 ms |
1952 KB |
Output is correct |
9 |
Correct |
75 ms |
6784 KB |
Output is correct |
10 |
Correct |
11 ms |
1308 KB |
Output is correct |
11 |
Correct |
57 ms |
5252 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
384 ms |
23312 KB |
Output is correct |
14 |
Correct |
211 ms |
14324 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
4 ms |
720 KB |
Output is correct |
17 |
Correct |
2 ms |
464 KB |
Output is correct |
18 |
Correct |
43 ms |
4380 KB |
Output is correct |
19 |
Correct |
96 ms |
10088 KB |
Output is correct |
20 |
Correct |
9 ms |
1296 KB |
Output is correct |
21 |
Correct |
6 ms |
976 KB |
Output is correct |
22 |
Correct |
7 ms |
976 KB |
Output is correct |
23 |
Correct |
2948 ms |
125696 KB |
Output is correct |
24 |
Correct |
1848 ms |
104080 KB |
Output is correct |
25 |
Correct |
5 ms |
720 KB |
Output is correct |
26 |
Correct |
10 ms |
1232 KB |
Output is correct |
27 |
Correct |
10 ms |
1296 KB |
Output is correct |
28 |
Correct |
7 ms |
976 KB |
Output is correct |
29 |
Correct |
9 ms |
1060 KB |
Output is correct |
30 |
Correct |
8 ms |
1104 KB |
Output is correct |
31 |
Correct |
6 ms |
976 KB |
Output is correct |
32 |
Correct |
2486 ms |
125588 KB |
Output is correct |
33 |
Correct |
3002 ms |
125508 KB |
Output is correct |
34 |
Correct |
1849 ms |
110904 KB |
Output is correct |
35 |
Correct |
3195 ms |
117112 KB |
Output is correct |
36 |
Correct |
158 ms |
14472 KB |
Output is correct |
37 |
Correct |
317 ms |
28728 KB |
Output is correct |
38 |
Correct |
118 ms |
12188 KB |
Output is correct |
39 |
Correct |
215 ms |
19512 KB |
Output is correct |
40 |
Correct |
80 ms |
9116 KB |
Output is correct |
41 |
Correct |
634 ms |
49352 KB |
Output is correct |
42 |
Correct |
17 ms |
3724 KB |
Output is correct |
43 |
Execution timed out |
4061 ms |
197776 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4075 ms |
198368 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4058 ms |
195156 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
720 KB |
Output is correct |
3 |
Correct |
4 ms |
652 KB |
Output is correct |
4 |
Correct |
3 ms |
592 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
20 ms |
1952 KB |
Output is correct |
9 |
Correct |
75 ms |
6784 KB |
Output is correct |
10 |
Correct |
11 ms |
1308 KB |
Output is correct |
11 |
Correct |
57 ms |
5252 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
384 ms |
23312 KB |
Output is correct |
14 |
Correct |
211 ms |
14324 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
4 ms |
720 KB |
Output is correct |
17 |
Correct |
2 ms |
464 KB |
Output is correct |
18 |
Correct |
43 ms |
4380 KB |
Output is correct |
19 |
Correct |
96 ms |
10088 KB |
Output is correct |
20 |
Correct |
9 ms |
1296 KB |
Output is correct |
21 |
Correct |
6 ms |
976 KB |
Output is correct |
22 |
Correct |
7 ms |
976 KB |
Output is correct |
23 |
Correct |
2948 ms |
125696 KB |
Output is correct |
24 |
Correct |
1848 ms |
104080 KB |
Output is correct |
25 |
Correct |
5 ms |
720 KB |
Output is correct |
26 |
Correct |
10 ms |
1232 KB |
Output is correct |
27 |
Correct |
10 ms |
1296 KB |
Output is correct |
28 |
Correct |
7 ms |
976 KB |
Output is correct |
29 |
Correct |
9 ms |
1060 KB |
Output is correct |
30 |
Correct |
8 ms |
1104 KB |
Output is correct |
31 |
Correct |
6 ms |
976 KB |
Output is correct |
32 |
Correct |
2486 ms |
125588 KB |
Output is correct |
33 |
Correct |
3002 ms |
125508 KB |
Output is correct |
34 |
Correct |
1849 ms |
110904 KB |
Output is correct |
35 |
Correct |
3195 ms |
117112 KB |
Output is correct |
36 |
Correct |
158 ms |
14472 KB |
Output is correct |
37 |
Correct |
317 ms |
28728 KB |
Output is correct |
38 |
Correct |
118 ms |
12188 KB |
Output is correct |
39 |
Correct |
215 ms |
19512 KB |
Output is correct |
40 |
Correct |
80 ms |
9116 KB |
Output is correct |
41 |
Correct |
634 ms |
49352 KB |
Output is correct |
42 |
Correct |
17 ms |
3724 KB |
Output is correct |
43 |
Execution timed out |
4061 ms |
197776 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4062 ms |
225600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |