#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define pb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
const ll inf=1001001001001;
#include "towers.h"
struct Sparsetable{
ll n;
vvi tablema,tablemi;
vi sz;
void init(vi v){
n=v.size();
tablema=vvi(18,vi(n));tablemi=vvi(18,vi(n));
tablema[0]=tablemi[0]=v;
rep(i,17)rep(j,n)if(j+(1<<(i+1))<=n){
tablema[i+1][j]=max(tablema[i][j],tablema[i][j+(1<<i)]);
tablemi[i+1][j]=min(tablemi[i][j],tablemi[i][j+(1<<i)]);
}
sz=vi(n+1);
rep(i,18)REP(j,1<<i,1<<(i+1))if(j<=n)sz[j]=i;
}
ll getma(ll l,ll r){
if(l>=r)return -inf;
ll res=-inf;
REP(i,l,r)chmax(res,tablema[0][i]);
return res;
///////////////////////////////////////////////////////////
ll s=sz[r-l];
return max(tablema[s][l],tablema[s][r-(1<<s)]);
}
ll getmi(ll l,ll r){
if(l>=r)return inf;
ll res=inf;
REP(i,l,r)chmin(res,tablemi[0][i]);
return res;
///////////////////////////////////////////////////////////
ll s=sz[r-l];
return min(tablemi[s][l],tablemi[s][r-(1<<s)]);
}
};
vi v,sp,dif;
vvi L,R;
ll n,m;
Sparsetable sps;
void init(int N,vector<int> H){
for(int x:H)v.pb(-x);
sps.init(v);
n=N;
rep(i,n)if((i==0||v[i-1]>v[i])&&(i==n-1||v[i+1]>v[i]))sp.pb(i);
m=sp.size();
L=vvi(18,vi(m,-1));R=vvi(18,vi(m,-1));
{
vi st;
for(int i=m-1;i>=0;i--){
while(st.size()&&v[sp[st.back()]]>v[sp[i]])st.pop_back();
if(st.size())R[0][i]=st.back();
st.pb(i);
}
}
{
vi st;
rep(i,m){
while(st.size()&&v[sp[st.back()]]>v[sp[i]])st.pop_back();
if(st.size())L[0][i]=st.back();
st.pb(i);
}
}
rep(i,17)rep(j,m)if(L[i][j]!=-1)L[i+1][j]=L[i][L[i][j]];
rep(i,17)rep(j,m)if(R[i][j]!=-1)R[i+1][j]=R[i][R[i][j]];
dif=vi(m);
rep(i,m){
P rng;
rng.fi=(L[0][i]==-1 ? 0 : sp[L[0][i]]+1);
rng.se=(R[0][i]==-1 ? n-1 : sp[R[0][i]]-1);
ll ma=min(sps.getma(rng.fi,sp[i]),sps.getma(sp[i]+1,rng.se+1));
dif[i]=ma-v[sp[i]];
}
}
int max_towers(int a, int b, int D){
ll l=lb(sp,a),r=lb(sp,b+1)-1;
if(l>r){
if(sps.getma(a+1,b)>=max(v[a],v[b])+D)return 2;
return 1;
}
ll l_=l,r_=r;
{
int cur=l;
while(cur!=-1&&cur<=r){
if(sps.getma(a,sp[cur])>=v[sp[cur]]+D)break;
l_=cur+1;
cur=R[0][cur];
}
}
{
int cur=r;
while(cur!=-1&&cur>=l){
if(sps.getma(sp[cur]+1,b+1)>=v[sp[cur]]+D)break;
r_=cur-1;
cur=L[0][cur];
}
}
ll mi=inf,ma=-inf;
int ans=0;
REP(i,l_,r_+1)if(dif[i]>=D){
ans++;
chmin(mi,i);
chmax(ma,i);
}
return ans+1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1090 ms |
19008 KB |
Output is correct |
2 |
Correct |
3895 ms |
31544 KB |
Output is correct |
3 |
Correct |
3996 ms |
31576 KB |
Output is correct |
4 |
Execution timed out |
4001 ms |
31616 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
1104 KB |
Output is correct |
3 |
Correct |
1 ms |
1104 KB |
Output is correct |
4 |
Correct |
1 ms |
1104 KB |
Output is correct |
5 |
Correct |
1 ms |
1104 KB |
Output is correct |
6 |
Correct |
1 ms |
1104 KB |
Output is correct |
7 |
Correct |
2 ms |
1104 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
848 KB |
Output is correct |
10 |
Correct |
1 ms |
848 KB |
Output is correct |
11 |
Correct |
1 ms |
848 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
848 KB |
Output is correct |
14 |
Correct |
1 ms |
848 KB |
Output is correct |
15 |
Correct |
1 ms |
1104 KB |
Output is correct |
16 |
Correct |
1 ms |
1104 KB |
Output is correct |
17 |
Correct |
1 ms |
1104 KB |
Output is correct |
18 |
Correct |
1 ms |
920 KB |
Output is correct |
19 |
Correct |
1 ms |
848 KB |
Output is correct |
20 |
Correct |
1 ms |
1104 KB |
Output is correct |
21 |
Correct |
1 ms |
1104 KB |
Output is correct |
22 |
Correct |
1 ms |
1104 KB |
Output is correct |
23 |
Correct |
1 ms |
848 KB |
Output is correct |
24 |
Correct |
1 ms |
848 KB |
Output is correct |
25 |
Correct |
1 ms |
592 KB |
Output is correct |
26 |
Correct |
1 ms |
1104 KB |
Output is correct |
27 |
Correct |
1 ms |
1112 KB |
Output is correct |
28 |
Correct |
1 ms |
1104 KB |
Output is correct |
29 |
Correct |
1 ms |
1104 KB |
Output is correct |
30 |
Correct |
1 ms |
1104 KB |
Output is correct |
31 |
Correct |
1 ms |
1104 KB |
Output is correct |
32 |
Correct |
1 ms |
848 KB |
Output is correct |
33 |
Correct |
1 ms |
848 KB |
Output is correct |
34 |
Correct |
1 ms |
848 KB |
Output is correct |
35 |
Correct |
1 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
1104 KB |
Output is correct |
3 |
Correct |
1 ms |
1104 KB |
Output is correct |
4 |
Correct |
1 ms |
1104 KB |
Output is correct |
5 |
Correct |
1 ms |
1104 KB |
Output is correct |
6 |
Correct |
1 ms |
1104 KB |
Output is correct |
7 |
Correct |
2 ms |
1104 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
848 KB |
Output is correct |
10 |
Correct |
1 ms |
848 KB |
Output is correct |
11 |
Correct |
1 ms |
848 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
848 KB |
Output is correct |
14 |
Correct |
1 ms |
848 KB |
Output is correct |
15 |
Correct |
1 ms |
1104 KB |
Output is correct |
16 |
Correct |
1 ms |
1104 KB |
Output is correct |
17 |
Correct |
1 ms |
1104 KB |
Output is correct |
18 |
Correct |
1 ms |
920 KB |
Output is correct |
19 |
Correct |
1 ms |
848 KB |
Output is correct |
20 |
Correct |
1 ms |
1104 KB |
Output is correct |
21 |
Correct |
1 ms |
1104 KB |
Output is correct |
22 |
Correct |
1 ms |
1104 KB |
Output is correct |
23 |
Correct |
1 ms |
848 KB |
Output is correct |
24 |
Correct |
1 ms |
848 KB |
Output is correct |
25 |
Correct |
1 ms |
592 KB |
Output is correct |
26 |
Correct |
1 ms |
1104 KB |
Output is correct |
27 |
Correct |
1 ms |
1112 KB |
Output is correct |
28 |
Correct |
1 ms |
1104 KB |
Output is correct |
29 |
Correct |
1 ms |
1104 KB |
Output is correct |
30 |
Correct |
1 ms |
1104 KB |
Output is correct |
31 |
Correct |
1 ms |
1104 KB |
Output is correct |
32 |
Correct |
1 ms |
848 KB |
Output is correct |
33 |
Correct |
1 ms |
848 KB |
Output is correct |
34 |
Correct |
1 ms |
848 KB |
Output is correct |
35 |
Correct |
1 ms |
848 KB |
Output is correct |
36 |
Correct |
23 ms |
26684 KB |
Output is correct |
37 |
Correct |
35 ms |
41064 KB |
Output is correct |
38 |
Correct |
34 ms |
40968 KB |
Output is correct |
39 |
Correct |
37 ms |
45772 KB |
Output is correct |
40 |
Correct |
37 ms |
45848 KB |
Output is correct |
41 |
Correct |
36 ms |
45824 KB |
Output is correct |
42 |
Correct |
37 ms |
45860 KB |
Output is correct |
43 |
Correct |
27 ms |
31640 KB |
Output is correct |
44 |
Correct |
26 ms |
31552 KB |
Output is correct |
45 |
Correct |
27 ms |
31584 KB |
Output is correct |
46 |
Correct |
27 ms |
31668 KB |
Output is correct |
47 |
Correct |
34 ms |
40944 KB |
Output is correct |
48 |
Correct |
37 ms |
45852 KB |
Output is correct |
49 |
Correct |
44 ms |
45980 KB |
Output is correct |
50 |
Correct |
27 ms |
31532 KB |
Output is correct |
51 |
Correct |
27 ms |
31672 KB |
Output is correct |
52 |
Correct |
37 ms |
40916 KB |
Output is correct |
53 |
Correct |
38 ms |
45856 KB |
Output is correct |
54 |
Correct |
43 ms |
45844 KB |
Output is correct |
55 |
Correct |
27 ms |
31624 KB |
Output is correct |
56 |
Correct |
27 ms |
31616 KB |
Output is correct |
57 |
Correct |
33 ms |
39380 KB |
Output is correct |
58 |
Correct |
34 ms |
40956 KB |
Output is correct |
59 |
Correct |
35 ms |
40956 KB |
Output is correct |
60 |
Correct |
37 ms |
45808 KB |
Output is correct |
61 |
Correct |
38 ms |
45852 KB |
Output is correct |
62 |
Correct |
37 ms |
45796 KB |
Output is correct |
63 |
Correct |
37 ms |
45808 KB |
Output is correct |
64 |
Correct |
27 ms |
31664 KB |
Output is correct |
65 |
Correct |
26 ms |
31660 KB |
Output is correct |
66 |
Correct |
27 ms |
31600 KB |
Output is correct |
67 |
Correct |
27 ms |
31612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1081 ms |
40596 KB |
59096th lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
913 ms |
10116 KB |
Output is correct |
2 |
Execution timed out |
4032 ms |
40988 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
1104 KB |
Output is correct |
3 |
Correct |
1 ms |
1104 KB |
Output is correct |
4 |
Correct |
1 ms |
1104 KB |
Output is correct |
5 |
Correct |
1 ms |
1104 KB |
Output is correct |
6 |
Correct |
1 ms |
1104 KB |
Output is correct |
7 |
Correct |
2 ms |
1104 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
848 KB |
Output is correct |
10 |
Correct |
1 ms |
848 KB |
Output is correct |
11 |
Correct |
1 ms |
848 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
848 KB |
Output is correct |
14 |
Correct |
1 ms |
848 KB |
Output is correct |
15 |
Correct |
1 ms |
1104 KB |
Output is correct |
16 |
Correct |
1 ms |
1104 KB |
Output is correct |
17 |
Correct |
1 ms |
1104 KB |
Output is correct |
18 |
Correct |
1 ms |
920 KB |
Output is correct |
19 |
Correct |
1 ms |
848 KB |
Output is correct |
20 |
Correct |
1 ms |
1104 KB |
Output is correct |
21 |
Correct |
1 ms |
1104 KB |
Output is correct |
22 |
Correct |
1 ms |
1104 KB |
Output is correct |
23 |
Correct |
1 ms |
848 KB |
Output is correct |
24 |
Correct |
1 ms |
848 KB |
Output is correct |
25 |
Correct |
1 ms |
592 KB |
Output is correct |
26 |
Correct |
1 ms |
1104 KB |
Output is correct |
27 |
Correct |
1 ms |
1112 KB |
Output is correct |
28 |
Correct |
1 ms |
1104 KB |
Output is correct |
29 |
Correct |
1 ms |
1104 KB |
Output is correct |
30 |
Correct |
1 ms |
1104 KB |
Output is correct |
31 |
Correct |
1 ms |
1104 KB |
Output is correct |
32 |
Correct |
1 ms |
848 KB |
Output is correct |
33 |
Correct |
1 ms |
848 KB |
Output is correct |
34 |
Correct |
1 ms |
848 KB |
Output is correct |
35 |
Correct |
1 ms |
848 KB |
Output is correct |
36 |
Correct |
23 ms |
26684 KB |
Output is correct |
37 |
Correct |
35 ms |
41064 KB |
Output is correct |
38 |
Correct |
34 ms |
40968 KB |
Output is correct |
39 |
Correct |
37 ms |
45772 KB |
Output is correct |
40 |
Correct |
37 ms |
45848 KB |
Output is correct |
41 |
Correct |
36 ms |
45824 KB |
Output is correct |
42 |
Correct |
37 ms |
45860 KB |
Output is correct |
43 |
Correct |
27 ms |
31640 KB |
Output is correct |
44 |
Correct |
26 ms |
31552 KB |
Output is correct |
45 |
Correct |
27 ms |
31584 KB |
Output is correct |
46 |
Correct |
27 ms |
31668 KB |
Output is correct |
47 |
Correct |
34 ms |
40944 KB |
Output is correct |
48 |
Correct |
37 ms |
45852 KB |
Output is correct |
49 |
Correct |
44 ms |
45980 KB |
Output is correct |
50 |
Correct |
27 ms |
31532 KB |
Output is correct |
51 |
Correct |
27 ms |
31672 KB |
Output is correct |
52 |
Correct |
37 ms |
40916 KB |
Output is correct |
53 |
Correct |
38 ms |
45856 KB |
Output is correct |
54 |
Correct |
43 ms |
45844 KB |
Output is correct |
55 |
Correct |
27 ms |
31624 KB |
Output is correct |
56 |
Correct |
27 ms |
31616 KB |
Output is correct |
57 |
Correct |
33 ms |
39380 KB |
Output is correct |
58 |
Correct |
34 ms |
40956 KB |
Output is correct |
59 |
Correct |
35 ms |
40956 KB |
Output is correct |
60 |
Correct |
37 ms |
45808 KB |
Output is correct |
61 |
Correct |
38 ms |
45852 KB |
Output is correct |
62 |
Correct |
37 ms |
45796 KB |
Output is correct |
63 |
Correct |
37 ms |
45808 KB |
Output is correct |
64 |
Correct |
27 ms |
31664 KB |
Output is correct |
65 |
Correct |
26 ms |
31660 KB |
Output is correct |
66 |
Correct |
27 ms |
31600 KB |
Output is correct |
67 |
Correct |
27 ms |
31612 KB |
Output is correct |
68 |
Incorrect |
1081 ms |
40596 KB |
59096th lines differ - on the 1st token, expected: '1', found: '2' |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1090 ms |
19008 KB |
Output is correct |
2 |
Correct |
3895 ms |
31544 KB |
Output is correct |
3 |
Correct |
3996 ms |
31576 KB |
Output is correct |
4 |
Execution timed out |
4001 ms |
31616 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |