#include <bits/stdc++.h>
#define int long long
using namespace std;
struct point {
int x, y;
};
const int MAX_N = 2.5e5;
const int MAX_X = 1e9;
const int MIN_X = -1e9;
point v[MAX_N];
struct AIB {
vector<int> pos;
vector<int> aib;
void init() {
pos.clear();
aib.clear();
}
void add( int i ) {
pos.push_back( i );
}
void prep() {
pos.push_back( -MAX_X - 1 );
sort( pos.begin(), pos.end() );
pos.resize( unique( pos.begin(), pos.end() ) - pos.begin() );
for ( int i = 0; i < pos.size(); i++ )
aib.push_back( 0 );
}
void clear() {
for ( int i = 0; i < aib.size(); i++ )
aib[i] = 0;
}
void update( int i, int x ) {
int l = 0, r = pos.size();
while ( r - l > 1 ) {
int p = (l + r) / 2;
if ( pos[p] > i )
r = p;
else
l = p;
}
i = l;
while ( i < aib.size() ) {
aib[i] += x;
i += (i & -i);
}
}
int query( int i ) {
int l = 0, r = pos.size();
while ( r - l > 1 ) {
int p = (l + r) / 2;
if ( pos[p] > i )
r = p;
else
l = p;
}
i = l;
int s = 0;
while ( i > 0 ) {
s += aib[i];
i -= (i & -i);
}
return s;
}
};
struct AIB2D {
vector<int> pos;
vector<AIB> aib;
vector<point> pts;
AIB emptyAIB;
void init() {
pos.clear();
aib.clear();
}
void add( int i, int j ) {
pts.push_back( { i, j } );
pos.push_back( i );
emptyAIB.init();
}
void prep() {
pos.push_back( -MAX_X - 1 );
sort( pos.begin(), pos.end() );
pos.resize( unique( pos.begin(), pos.end() ) - pos.begin() );
for ( int i = 0; i < pos.size(); i++ )
aib.push_back( emptyAIB );
for ( point q: pts ) {
int l = 0, r = pos.size();
while ( r - l > 1 ) {
int p = (l + r) / 2;
if ( pos[p] > q.x )
r = p;
else
l = p;
}
int i = l;
while ( i < aib.size() ) {
aib[i].add( q.y );
i += (i & -i);
}
}
for ( int i = 0; i < pos.size(); i++ )
aib[i].prep();
}
void clear() {
for ( int i = 0; i < aib.size(); i++ )
aib[i].clear();
}
void update( int i, int j, int x ) {
int l = 0, r = pos.size();
while ( r - l > 1 ) {
int p = (l + r) / 2;
if ( pos[p] > i )
r = p;
else
l = p;
}
if ( pos[l] != i )
exit( 1 );
i = l;
while ( i < aib.size() ) {
aib[i].update( j, x );
i += (i & -i);
}
}
int query( int i, int j ) {
int l = 0, r = pos.size();
while ( r - l > 1 ) {
int p = (l + r) / 2;
if ( pos[p] > i )
r = p;
else
l = p;
}
i = l;
int s = 0;
while ( i > 0 ) {
s += aib[i].query( j );
i -= (i & -i);
}
return s;
}
} leftPoints, rightPoints;
signed main() {
int n, k;
cin >> n >> k;
for ( int i = 0; i < n; i++ )
cin >> v[i].x >> v[i].y;
sort( v, v + n, []( point a, point b ) {
if ( a.x == b.x )
return a.y < b.y;
return a.x < b.x;
} );
leftPoints.init();
rightPoints.init();
for ( int i = 0; i < n; i++ ) {
leftPoints.add( v[i].y, -v[i].x - v[i].y );
rightPoints.add( v[i].y, -v[i].x + v[i].y );
}
leftPoints.prep();
rightPoints.prep();
int ld = 0, rd = 2 * (MAX_X - MIN_X);
while ( rd - ld > 1 ) {
int d = (ld + rd) / 2;
int pairs = 0;
leftPoints.clear();
rightPoints.clear();
for ( int i = 0; i < n; i++ ) {
pairs += leftPoints.query( v[i].y, d - (v[i].x + v[i].y) );
pairs += rightPoints.query( MAX_X, d - (v[i].x - v[i].y) ) - rightPoints.query( v[i].y, d - (v[i].x - v[i].y) );
leftPoints.update( v[i].y, -v[i].x - v[i].y, 1 );
rightPoints.update( v[i].y, -v[i].x + v[i].y, 1 );
}
if ( pairs < k )
ld = d;
else
rd = d;
}
int d = rd;
vector<int> sol;
for ( int i = 0; i < n; i++ ) {
for ( int j = i + 1; j < n; j++ ) {
if ( abs( v[i].x - v[j].x ) + abs( v[i].y - v[j].y ) < d )
sol.push_back( abs( v[i].x - v[j].x ) + abs( v[i].y - v[j].y ) );
}
}
while ( sol.size() < k )
sol.push_back( d );
sort( sol.begin(), sol.end() );
for( int x: sol )
cout << x << "\n";
return 0;
}
Compilation message
road_construction.cpp: In member function 'void AIB::prep()':
road_construction.cpp:33:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for ( int i = 0; i < pos.size(); i++ )
| ~~^~~~~~~~~~~~
road_construction.cpp: In member function 'void AIB::clear()':
road_construction.cpp:38:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for ( int i = 0; i < aib.size(); i++ )
| ~~^~~~~~~~~~~~
road_construction.cpp: In member function 'void AIB::update(long long int, long long int)':
road_construction.cpp:52:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | while ( i < aib.size() ) {
| ~~^~~~~~~~~~~~
road_construction.cpp: In member function 'void AIB2D::prep()':
road_construction.cpp:98:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for ( int i = 0; i < pos.size(); i++ )
| ~~^~~~~~~~~~~~
road_construction.cpp:110:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<AIB>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | while ( i < aib.size() ) {
| ~~^~~~~~~~~~~~
road_construction.cpp:115:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for ( int i = 0; i < pos.size(); i++ )
| ~~^~~~~~~~~~~~
road_construction.cpp: In member function 'void AIB2D::clear()':
road_construction.cpp:120:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<AIB>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
120 | for ( int i = 0; i < aib.size(); i++ )
| ~~^~~~~~~~~~~~
road_construction.cpp: In member function 'void AIB2D::update(long long int, long long int, long long int)':
road_construction.cpp:136:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<AIB>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
136 | while ( i < aib.size() ) {
| ~~^~~~~~~~~~~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:214:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
214 | while ( sol.size() < k )
| ~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10040 ms |
860 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10018 ms |
26516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10028 ms |
173352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10028 ms |
173352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10040 ms |
860 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10040 ms |
860 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |