#include <bits/stdc++.h>
using namespace std;
long long N,K,ft[250005],ans[250005];
pair<long long,long long> lst[250005];
vector< tuple<long long,long long,long long,long long> > A;
vector<long long> dis;
void update (long long x, long long v) {
x++;
while (x <= N) ft[x] += v, x += x & -x;
}
long long query (long long x) {
x++;
long long ans = 0;
while (x) ans += ft[x], x -= x & -x;
return ans;
}
void dnc (long long l, long long r, long long x, long long y) {
if (l == r) {
for (long long i = x; i <= y; ++i) ans[i] = l;
return;
}
long long mid = (l+r)/2;
A.clear();
for (long long i = 0; i < N; ++i) {
long long a = lower_bound(dis.begin(),dis.end(),lst[i].second) - dis.begin();
long long b = lower_bound(dis.begin(),dis.end(),lst[i].second-mid) - dis.begin();
long long c = upper_bound(dis.begin(),dis.end(),lst[i].second+mid) - dis.begin() - 1;
A.emplace_back(lst[i].first,0,a,0);
A.emplace_back(lst[i].first-mid,-1,b,c);
A.emplace_back(lst[i].first+mid,1,b,c);
}
sort(A.begin(),A.end());
for (long long i = 0; i <= N; ++i) ft[i] = 0;
long long ans = -N;
for (auto x: A) {
long long a,b,c,d; tie(a,b,c,d) = x;
if (b == 0) ans += query(c);
if (b == -1) update(c,1), update(d+1,-1);
if (b == 1) update(c,-1), update(d+1,1);
}
if (x <= ans/2) dnc(l,mid,x,min(ans/2,y));
if (ans/2+1 <= y) dnc(mid+1,r,max(x,ans/2+1),y);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> N >> K;
for (long long i = 0; i < N; ++i) {
long long x,y; cin >> x >> y;
lst[i] = make_pair(x-y,x+y);
dis.push_back(lst[i].second);
}
sort(dis.begin(),dis.end());
dis.resize(unique(dis.begin(),dis.end()) - dis.begin());
dnc(0,4e9+5,1,K);
for (long long i = 1; i <= K; ++i) cout << ans[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10070 ms |
596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10048 ms |
39084 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6164 ms |
39112 KB |
Output is correct |
2 |
Correct |
6008 ms |
39088 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
5626 ms |
39108 KB |
Output is correct |
5 |
Correct |
4714 ms |
39060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6164 ms |
39112 KB |
Output is correct |
2 |
Correct |
6008 ms |
39088 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
5626 ms |
39108 KB |
Output is correct |
5 |
Correct |
4714 ms |
39060 KB |
Output is correct |
6 |
Execution timed out |
10041 ms |
39116 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10070 ms |
596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10070 ms |
596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |