이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 5e9;
int n,cate;
pair<int,int> v[250005];
pair<int,int> p[250005];
int aib[750005];
int qry(int poz)
{
int aux=0;
for(int i=poz;i>0;i-=(i&(-i)))
aux += aib[i];
return aux;
}
void upd(int poz, int newv)
{
for(int i=poz;i<=cate;i+=(i&(-i)))
aib[i] += newv;
}
map<int,int> mp,nrm;
int numara(int lim)
{
mp.clear();
nrm.clear();
for(int i=1;i<=n;i++)
{
p[i].first = v[i].first + v[i].second;
p[i].second = v[i].first - v[i].second;
mp[p[i].second]++;
mp[p[i].second+lim]++;
mp[p[i].second-lim-1]++;
}
cate=0;
for(auto it:mp)
if(it.second)
nrm[it.first]=++cate;
sort(p+1,p+1+n);
int poz=1,cnt=0;
for(int i=1;i<=n;i++)
{
while(p[i].first-p[poz].first>lim)
{
upd(nrm[p[poz].second],-1);
poz++;
}
cnt += qry(nrm[p[i].second+lim]) - qry(nrm[p[i].second-lim-1]);
upd(nrm[p[i].second],+1);
}
while(poz<=n)
{
upd(nrm[p[poz].second],-1);
poz++;
}
return cnt;
}
void afis(int lim)
{
for(int i=1;i<=n;i++)
{
p[i].first = v[i].first + v[i].second;
p[i].second = v[i].first - v[i].second;
}
sort(p+1,p+1+n);
int poz=1;
set<pair<int,int>> s;
vector<int> sol;
for(int i=1;i<=n;i++)
{
while(p[i].first-p[poz].first>lim)
{
s.erase({p[poz].second,poz});
poz++;
}
auto it = s.lower_bound({p[i].second-lim,-1});
while(it!=s.end())
{
if((*it).first > p[i].second+lim)
break;
sol.push_back(max(abs(p[i].first-p[(*it).second].first),abs(p[i].second-p[(*it).second].second)));
it++;
}
s.insert({p[i].second,i});
}
sort(sol.begin(),sol.end());
for(auto x:sol)
cout<<x<<"\n";
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int k;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>v[i].first>>v[i].second;
}
int st=0,dr=INF,ans=0;
while(st<=dr)
{
int mij=(st+dr)/2;
if(numara(mij)<=k)
{
ans=mij;
st=mij+1;
}
else
dr=mij-1;
}
afis(ans);
for(int i=1;i<=k-numara(ans);i++)
cout<<ans+1<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |