#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include"bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991
#define MN -1000000001
const int maxn = 150001;
const int dx[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dy[] = { 0, 0, 1, -1, -1, 1, -1, 1};
// 0 4 6 2 3 5 1 7
const int roundx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int roundy[] = {0, 1, 1, 1, 0, -1, -1, -1};
int ddd[] = {0,4,6,2,3,5,1,7};
struct cell {int x, y, id;};
struct neal {
static uint64_t splitmix64(uint64_t x)
{
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
{
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
// #define HASH(a,b) (1000000000ll*b+a)
long long HASH (int a, int b) {
return (long long)a + 1000000000ll*b;
}
int n, t, ID = 0, buf;
int x[maxn], y[maxn];
cell cells[maxn];
int dsu[4 * maxn];
vector<pair<int,int>> vec[4 * maxn];
bool out[4 * maxn];
bool FF[4*maxn][8];
pair<int,int> mp[4 * maxn];
unordered_set<long long> S;
unordered_map<int,int> Empty, Full; // maps cell to dsu
set<cell> active, expendable;
bool operator < (const cell& a, const cell& b) {
return a.id > b.id;
}
int Find (int x) {
return dsu[x] == x ? x : dsu[x] = Find(dsu[x]);
}
void check (const cell &c) {
auto [u, v, id] = c;
int prev = -1;
bool artic = 0, sep = 0;
vector<int> to_reset;
// for (int d = 0 ; d < 8 ; d++) {
// int u2 = u + roundx[d];
// int v2 = v + roundy[d];
// if (S.count(HASH(u2,v2))) FF[id][d] = 1;
// else FF[id][d] = 0;
// }
for (int w = 0 ; w < 9 ; w++) {
int d = w%8;
int u2 = u + roundx[d];
int v2 = v + roundy[d];
if (FF[id][d]) sep = 1;
else {
if (d & 1) {
continue;
}
int cmp = Find(Empty[HASH(u2,v2)]);
if (mp[cmp].first != MN and sep == 1) {
auto [pu, pv] = mp[cmp];
bool bad = 0;
for (int ww = w ; ; ww++) {
int d2 = ww % 8;
int u3 = u + roundx[d2];
int v3 = v + roundy[d2];
if (u3 == pu and v3 == pv) {
break;
}
else {
if (FF[id][d2]) {
bad = 1;
break;
}
}
}
if (bad) artic = 1;
}
mp[cmp] = {u2, v2};
to_reset.push_back(cmp);
sep = 0;
prev = cmp;
}
}
for (int cmp : to_reset) {
mp[cmp] = {MN,-1};
}
bool isout = 0;
if (!artic) {
for (int d = 0 ; d < 4 ; d++) {
int u2 = u + dx[d];
int v2 = v + dy[d];
if (Empty.count(HASH(u2,v2))) {
int cmp = Find(Empty[HASH(u2,v2)]);
if (out[cmp]) isout = 1;
}
}
}
if (isout and !artic) expendable.insert(c);
else expendable.erase(c);
}
void Union (int a, int b) {
int x = Find(a), y = Find(b);
if (x == y) return;
if (vec[x].size() < vec[y].size()) {
out[y] |= out[x];
dsu[x] = y;
for (auto [u, v] : vec[x]) {
vec[y].push_back({u, v});
for (int d = 0 ; d < 8 ; d++) {
if (Full.count(HASH(u + dx[d],v + dy[d]))) check(cells[Full[HASH(u + dx[d],v + dy[d])]]);
}
}
vec[x].clear();
} else {
out[x] |= out[y];
dsu[y] = x;
for (auto [u, v] : vec[y]) {
vec[x].push_back({u, v});
for (int d = 0 ; d < 8 ; d++) {
if (Full.count(HASH(u + dx[d],v + dy[d]))) check(cells[Full[HASH(u + dx[d],v + dy[d])]]);
}
}
vec[y].clear();
}
}
signed main () {
cin.tie(0)->sync_with_stdio(0);
Empty.reserve(4*262144);
Full.reserve(4*262144);
Empty.max_load_factor(0.25);
Full.max_load_factor(0.25);
cin >> n >> t;
for (auto& [i, j] : mp) i = j = MN;
for (int i = 0 ; i < n ; i++) {
cin >> x[i] >> y[i];
cells[i] = {x[i], y[i], i};
Full[HASH(x[i],y[i])] = i;
S.insert(HASH(x[i], y[i]));
active.insert(cells[i]);
}
if (n > 1) {
for (int i = 0 ; i < n ; i++) {
bool good = 0;
for (int d = 0 ; d < 8 ; d++) {
int u = x[i] + dx[d];
int v = y[i] + dy[d];
good |= Full.count(HASH(u,v));
}
if (!good) {
cout << "NO\n";
return 0;
}
}
}
/* set at leat one node as out (for reference) */ {
pair<int,int> mn = {x[0], y[0]};
for (int i = 0 ; i < n ; i++) {
mn = min(mn, {x[i], y[i]});
}
auto [u, v] = mn; u--;
int id = Empty[HASH(u,v)] = ID++;
dsu[id] = id;
vec[id].push_back({u, v});
out[id] = 1;
}
for (int i = 0 ; i < n ; i++) {
for (int d = 0 ; d < 8 ; d++) {
int u = x[i] + dx[d];
int v = y[i] + dy[d];
if (!S.count(HASH(u,v)) and !Empty.count(HASH(u,v))) {
int id = Empty[HASH(u,v)] = ID++;
dsu[id] = id;
vec[id].push_back({u, v});
}
}
}
for (int i = 0 ; i < n ; i++) {
for (int d = 0 ; d < 8 ; d++) {
int u = x[i] + dx[d];
int v = y[i] + dy[d];
if (!S.count(HASH(u,v))) {
for (int d2 = 0 ; d2 < 4 ; d2++) {
int u2 = u + dx[d2];
int v2 = v + dy[d2];
if (Empty.count(HASH(u2,v2))) {
Union(Empty[HASH(u,v)], Empty[HASH(u2,v2)]);
}
}
} else {
FF[Full[HASH(u, v)]][ddd[d]] = 1;
}
}
}
for (int i = 0 ; i < n ; i++) check(cells[i]);
cout << "YES\n";
vector<int> ans;
while (expendable.size()) {
auto [a, b, c] = *expendable.begin();
expendable.erase(expendable.begin());
ans.push_back(c + 1);
Full.erase(HASH(a,b));
S.erase(HASH(a, b));
int id = Empty[HASH(a,b)] = ID++;
dsu[id] = id;
vec[id].push_back({a, b});
for (int d = 0 ; d < 4 ; d++) {
int u = a + dx[d];
int v = b + dy[d];
if (Empty.count(HASH(u,v))) {
Union(Empty[HASH(u,v)], id);
}
}
for (int d = 0 ; d < 8 ; d++) {
int u = a + dx[d];
int v = b + dy[d];
if (S.count(HASH(u,v))) {
check(cells[Full[HASH(u,v)]]);
FF[Full[HASH(u, v)]][ddd[d]] = 0;
}
}
}
reverse(ans.begin(), ans.end());
for (int i : ans) cout << i << "\n";
}
Compilation message
skyscrapers.cpp:17:1: warning: multi-line comment [-Wcomment]
17 | //\
| ^
skyscrapers.cpp: In function 'void check(const cell&)':
skyscrapers.cpp:75:9: warning: variable 'prev' set but not used [-Wunused-but-set-variable]
75 | int prev = -1;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
40404 KB |
ans=YES N=1 |
2 |
Correct |
22 ms |
40360 KB |
ans=YES N=4 |
3 |
Correct |
23 ms |
40336 KB |
ans=NO N=4 |
4 |
Correct |
22 ms |
40360 KB |
ans=YES N=5 |
5 |
Correct |
22 ms |
40328 KB |
ans=YES N=9 |
6 |
Correct |
22 ms |
40404 KB |
ans=YES N=5 |
7 |
Correct |
22 ms |
40320 KB |
ans=NO N=9 |
8 |
Correct |
22 ms |
40276 KB |
ans=NO N=10 |
9 |
Incorrect |
22 ms |
40340 KB |
Unexpected end of file - int32 expected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
40404 KB |
ans=YES N=1 |
2 |
Correct |
22 ms |
40360 KB |
ans=YES N=4 |
3 |
Correct |
23 ms |
40336 KB |
ans=NO N=4 |
4 |
Correct |
22 ms |
40360 KB |
ans=YES N=5 |
5 |
Correct |
22 ms |
40328 KB |
ans=YES N=9 |
6 |
Correct |
22 ms |
40404 KB |
ans=YES N=5 |
7 |
Correct |
22 ms |
40320 KB |
ans=NO N=9 |
8 |
Correct |
22 ms |
40276 KB |
ans=NO N=10 |
9 |
Incorrect |
22 ms |
40340 KB |
Unexpected end of file - int32 expected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
40404 KB |
ans=YES N=1 |
2 |
Correct |
22 ms |
40360 KB |
ans=YES N=4 |
3 |
Correct |
23 ms |
40336 KB |
ans=NO N=4 |
4 |
Correct |
22 ms |
40360 KB |
ans=YES N=5 |
5 |
Correct |
22 ms |
40328 KB |
ans=YES N=9 |
6 |
Correct |
22 ms |
40404 KB |
ans=YES N=5 |
7 |
Correct |
22 ms |
40320 KB |
ans=NO N=9 |
8 |
Correct |
22 ms |
40276 KB |
ans=NO N=10 |
9 |
Incorrect |
22 ms |
40340 KB |
Unexpected end of file - int32 expected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
40640 KB |
ans=NO N=1934 |
2 |
Correct |
26 ms |
40700 KB |
ans=NO N=1965 |
3 |
Incorrect |
31 ms |
40788 KB |
Full cells must be connected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
40404 KB |
ans=YES N=1 |
2 |
Correct |
22 ms |
40360 KB |
ans=YES N=4 |
3 |
Correct |
23 ms |
40336 KB |
ans=NO N=4 |
4 |
Correct |
22 ms |
40360 KB |
ans=YES N=5 |
5 |
Correct |
22 ms |
40328 KB |
ans=YES N=9 |
6 |
Correct |
22 ms |
40404 KB |
ans=YES N=5 |
7 |
Correct |
22 ms |
40320 KB |
ans=NO N=9 |
8 |
Correct |
22 ms |
40276 KB |
ans=NO N=10 |
9 |
Incorrect |
22 ms |
40340 KB |
Unexpected end of file - int32 expected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
51924 KB |
ans=NO N=66151 |
2 |
Correct |
74 ms |
51516 KB |
ans=NO N=64333 |
3 |
Incorrect |
587 ms |
57044 KB |
Full cells must be connected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
40640 KB |
ans=NO N=1934 |
2 |
Correct |
26 ms |
40700 KB |
ans=NO N=1965 |
3 |
Incorrect |
31 ms |
40788 KB |
Full cells must be connected |
4 |
Halted |
0 ms |
0 KB |
- |