#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
using mim = pair<pair<int,int>,int>;
const int maxn=1e5+10;
const int logg=18;
int n;
int h[maxn];
multiset<int> res;
mim sparse[logg][maxn];
int klk;
int suff[maxn];
int uniq[maxn];
mim comb(mim &a,mim &b){
mim ret=a;
ret.first=max(ret.first,b.first);
ret.second=min(ret.second,b.second);
return ret;
}
mim qry(int l,int r){
mim ret={{h[l],l},h[l]};
for(int i=logg-1;i>=0;i--){
if(r-(1<<i)+1>=l){
ret=comb(ret,sparse[i][r]);
r-=(1<<i);
}
}
return ret;
}
void resi(int l,int r,multiset<int> &ret,int naj=2e9+10){
if(r<l) return;
auto temp=qry(l,r);
pair<int,int> maxi=temp.first;
int mini=temp.second;
multiset<int> levi; multiset<int> desni;
resi(l,maxi.second-1,levi,maxi.first);
resi(maxi.second+1,r,desni,maxi.first);
if(levi.size()>desni.size()) swap(levi,desni);
for(int i:desni) levi.emplace(i);
if(!levi.empty()){
auto najv=--levi.end();
int d=naj-mini;
if(*najv<d){
levi.erase(najv);
levi.emplace(d);
}
}else{
levi.emplace(naj-mini);
}
swap(ret,levi);
}
void init(int _n, vector<int> _h) {
n=_n;
for(int i=0;i<n;i++) h[i]=_h[i];
for(int i=0;i<logg;i++){
for(int j=0;j<n;j++){
if(i==0) sparse[i][j]={{h[j],j},h[j]};
else if(j-(1<<(i-1))>=0) sparse[i][j]=comb(sparse[i-1][j],sparse[i-1][j-(1<<(i-1))]);
else sparse[i][j]=sparse[i-1][j];
}
}
resi(0,n-1,res);
klk=0;
for(int i:res) uniq[klk++]=i;
klk=unique(uniq,uniq+klk)-uniq;
int tren=0;
for(int i:res){
if(uniq[tren]!=i) tren++;
suff[tren]++;
}
for(int i=klk-2;i>=0;i--) suff[i]+=suff[i+1];
}
int max_towers(int l, int r, int d) {
int koji=lower_bound(uniq,uniq+klk,d)-uniq;
if(koji==klk) return 0;
return suff[koji];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
306 ms |
24264 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
464 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
464 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
686 ms |
25104 KB |
1st lines differ - on the 1st token, expected: '11903', found: '33010' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
277 ms |
6480 KB |
Output is correct |
2 |
Correct |
759 ms |
25896 KB |
Output is correct |
3 |
Correct |
638 ms |
25524 KB |
Output is correct |
4 |
Correct |
848 ms |
27312 KB |
Output is correct |
5 |
Correct |
827 ms |
26612 KB |
Output is correct |
6 |
Correct |
786 ms |
26628 KB |
Output is correct |
7 |
Correct |
746 ms |
26936 KB |
Output is correct |
8 |
Correct |
656 ms |
44488 KB |
Output is correct |
9 |
Correct |
777 ms |
44520 KB |
Output is correct |
10 |
Correct |
675 ms |
35700 KB |
Output is correct |
11 |
Correct |
606 ms |
37436 KB |
Output is correct |
12 |
Correct |
89 ms |
25644 KB |
Output is correct |
13 |
Correct |
111 ms |
27132 KB |
Output is correct |
14 |
Correct |
112 ms |
26616 KB |
Output is correct |
15 |
Correct |
62 ms |
44460 KB |
Output is correct |
16 |
Correct |
60 ms |
42428 KB |
Output is correct |
17 |
Correct |
98 ms |
24620 KB |
Output is correct |
18 |
Correct |
87 ms |
25408 KB |
Output is correct |
19 |
Correct |
88 ms |
25360 KB |
Output is correct |
20 |
Correct |
112 ms |
27032 KB |
Output is correct |
21 |
Correct |
107 ms |
26668 KB |
Output is correct |
22 |
Correct |
108 ms |
27272 KB |
Output is correct |
23 |
Correct |
104 ms |
26568 KB |
Output is correct |
24 |
Correct |
59 ms |
44488 KB |
Output is correct |
25 |
Correct |
60 ms |
44456 KB |
Output is correct |
26 |
Correct |
55 ms |
35872 KB |
Output is correct |
27 |
Correct |
64 ms |
43176 KB |
Output is correct |
28 |
Correct |
2 ms |
848 KB |
Output is correct |
29 |
Correct |
2 ms |
976 KB |
Output is correct |
30 |
Correct |
2 ms |
848 KB |
Output is correct |
31 |
Correct |
1 ms |
1232 KB |
Output is correct |
32 |
Correct |
1 ms |
1104 KB |
Output is correct |
33 |
Correct |
1 ms |
592 KB |
Output is correct |
34 |
Correct |
2 ms |
848 KB |
Output is correct |
35 |
Correct |
2 ms |
848 KB |
Output is correct |
36 |
Correct |
2 ms |
848 KB |
Output is correct |
37 |
Correct |
2 ms |
848 KB |
Output is correct |
38 |
Correct |
2 ms |
976 KB |
Output is correct |
39 |
Correct |
2 ms |
848 KB |
Output is correct |
40 |
Correct |
1 ms |
1232 KB |
Output is correct |
41 |
Correct |
1 ms |
1232 KB |
Output is correct |
42 |
Correct |
1 ms |
1104 KB |
Output is correct |
43 |
Correct |
1 ms |
1232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
464 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
306 ms |
24264 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |