2023 rcpc
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/// Gheorghies Alexandru - difference arrays solution
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
typedef long long ll;
|
||||
typedef long double ld;
|
||||
typedef pair<ll,ll> pll;
|
||||
typedef pair<ld,ld> pld;
|
||||
|
||||
const ll LGMAX=20,NMAX=2e5+5;
|
||||
vector<ll> smen[NMAX]; /// smen (smenul lui mars) is the romanian term for difference arrays
|
||||
ll ans[NMAX];
|
||||
pll v[NMAX];
|
||||
void tc(){
|
||||
ll n,k;
|
||||
cin>>n>>k;
|
||||
for(ll i=0;i<n;i++){
|
||||
cin>>v[i].first;
|
||||
v[i].second=i;
|
||||
}
|
||||
sort(v,v+n);
|
||||
ll r=0;
|
||||
for(ll l=0;l<n;l++){
|
||||
while(r<n && v[r].first-v[l].first<=k) r++;
|
||||
smen[l].push_back(r-l);
|
||||
smen[r].push_back(l-r); // -(r-l)
|
||||
}
|
||||
multiset<ll> cnd;
|
||||
for(ll i=0;i<n;i++){
|
||||
for(auto it : smen[i]){
|
||||
if(it>0) cnd.insert(it);
|
||||
else cnd.erase(cnd.lower_bound(-it));
|
||||
}
|
||||
ans[v[i].second]=*cnd.rbegin();
|
||||
}
|
||||
for(ll i=0;i<n;i++)
|
||||
cout<<ans[i]<<' ';
|
||||
}
|
||||
int main()
|
||||
{
|
||||
#ifndef ONLINE_JUDGE
|
||||
freopen("in.txt","r",stdin);
|
||||
freopen("out.txt","w",stdout);
|
||||
#endif // ONLINE_JUDGE
|
||||
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
|
||||
//ll t; cin>>t; while(t--)
|
||||
tc();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user