# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1062081 | MarwenElarbi | Radio Towers (IOI22_towers) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#include "towers.h"
#define pb push_back
#define ll long long
#define fi first
#define se second
const int nax=1e5+5;
int n;
vector<int> tab,cor;
int segtree[nax*4][2];
void update(int pos,int l,int r,int idx,int value,int type){
if(l==r){
segtree[pos][type]=value;
return;
}
int mid=(r+l)/2;
if(idx<=mid) update(pos*2+1,l,mid,idx,value,type);
else update(pos*2+2,mid+1,r,idx,value,type);
segtree[pos][type]=max(segtree[pos*2+1][type],segtree[pos*2+2][type]);
}
int query(int pos,int l,int r,int left,int right,int type){
if(l>r||l>right||r<left) return 0;
if(l>=left&&r<=right) return segtree[pos][type];
int mid=(r+l)/2;
return max(query(pos*2+1,l,mid,left,right,type),query(pos*2+2,mid+1,r,left,right,type));
}
void init(int N, std::vector<int> H) {
n=N;
for (int i = 0; i < N; ++i)
{
tab.pb(H[i]);
}
cor=tab;
sort(cor.begin(),cor.end());
}
int max_towers(int L, int R, int D){
int dp[n],dp1[n];
for (int i = L; i <= R; ++i)
{
int cur=upper_bound(cor.begin(),cor.end(),tab[i]-D)-cor.begin();
int pos=lower_bound(cor.begin(),cor.end(),tab[i])-cor.begin();
cur--;
dp1[i]=query(0,0,n-1,0,cur,0);
update(0,0,n-1,pos,dp1[i],1);
cur=lower_bound(cor.begin(),cor.end(),tab[i]+D)-cor.begin();
dp[i]=query(0,0,n-1,cur,n-1,1)+1;
update(0,0,n-1,pos,dp[i],0);
ans=max(ans,dp[i]);
}
return ans;
}