QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56925 | #3873. Towers | Janus | 0 | 555ms | 102780kb | C++ | 6.2kb | 2022-10-21 21:57:39 | 2022-10-21 21:57:40 |
Judging History
answer
#include<bits/stdc++.h>
#define MAXN 1000001
using namespace std;
struct coor{ int x, y, id; };
bool operator < (coor a, coor b){
if(a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
bool operator > (coor a, coor b){
if(a.x == b.x) return a.y > b.y;
return a.x > b.x;
}
bool operator < (coor a, int b){ return a.y < b; }
bool operator > (coor a, int b){ return a.y > b; }
int n, nx, ny;
int dx[MAXN], dy[MAXN];
coor tower[MAXN];
namespace gouzao{
vector<coor> tx[MAXN]; // x 坐标为 i 的塔的集合
int idx[MAXN]; // x 坐标为 i 时所选择的 y 坐标较小的塔
int ans[MAXN], res[MAXN], siz[MAXN];
void from_r_to_l(int op){
priority_queue<int> cy[MAXN]; // y 坐标为 i 时已选择的塔的 x 坐标的集合
priority_queue<int> q;
for(int i = 1; i <= n; i++) if(ans[tower[i].id]) cy[tower[i].y].push(tower[i].x);
for(int i = 1; i <= nx; i++) idx[i] = siz[i] - 1;
for(int i = ny; i >= 1; i--){
if(cy[i].empty()) continue;
cy[i].pop();
while(cy[i].size() > 1){
int now = cy[i].top(); cy[i].pop();
idx[now] = lower_bound(tx[now].begin(), tx[now].begin() + idx[now] + 1, i) - tx[now].begin();
if(idx[now] - op < 0) continue;
if(ans[tx[now][idx[now]].id] == 0) continue;
ans[tx[now][idx[now]].id] = 0; idx[now]--;
if(idx[now] >= 0 && ans[tx[now][idx[now]].id] == 0){
cy[tx[now][idx[now]].y].push(now);
ans[tx[now][idx[now]].id] = 1;
}
}
}
// for(int i = ny; i >= 1; i--){
// if(cy[i].size() > 2) q.push(i);
// }
// while(!q.empty()){
// int i = q.top();
// cy[i].pop();
// while(cy[i].size() > 1){
// int now = cy[i].top(); cy[i].pop();
// idx[now] = lower_bound(tx[now].begin(), tx[now].begin() + idx[now] + 1, i) - tx[now].begin();
// if(idx[now] - op < 0) continue;
// if(ans[tx[now][idx[now]].id] == 0) continue;
// ans[tx[now][idx[now]].id] = 0; idx[now]--;
// if(idx[now] >= 0 && ans[tx[now][idx[now]].id] == 0){
// int nowy = tx[now][idx[now]].y;
// cy[nowy].push(now);
// if(cy[nowy].size() > 2) q.push(nowy);
// ans[tx[now][idx[now]].id] = 1;
// }
// }
// }
}
void from_l_to_r(int op){
priority_queue<int> cy[MAXN]; // y 坐标为 i 时已选择的塔的 x 坐标的集合
for(int i = 1; i <= n; i++) if(ans[tower[i].id]) cy[tower[i].y].push(tower[i].x);
for(int i = 1; i <= nx; i++) idx[i] = 0;
for(int i = 1; i <= ny; i++){
if(cy[i].empty()) continue;
cy[i].pop();
while(cy[i].size() > 1){
int now = cy[i].top(); cy[i].pop();
idx[now] = lower_bound(tx[now].begin() + idx[now], tx[now].end(), i) - tx[now].begin();
if(idx[now] + op >= siz[now]) continue;
if(ans[tx[now][idx[now]].id] == 0) continue;
ans[tx[now][idx[now]].id] = 0; idx[now]++;
if(idx[now] < siz[now] && ans[tx[now][idx[now]].id] == 0){
cy[tx[now][idx[now]].y].push(now);
ans[tx[now][idx[now]].id] = 1;
}
}
}
}
void radix_sort(int n, coor a[]){
coor *b = new coor[n];
int *cnt = new int[1 << 16];
int mask = (1 << 16) - 1;
coor *x = a, *y = b;
for(int i = 0; i < 32; i += 16){
for(int j = 0; j < (1 << 16); j++) cnt[j] = 0;
for(int j = 0; j < n; j++) ++cnt[x[j].y >> i & mask];
for(int sum = 0, j = 0; j < (1 << 16); j++){
sum += cnt[j]; cnt[j] = sum - cnt[j];
}
for(int j = 0; j < n; j++) y[cnt[x[j].y >> i & mask]++] = x[j];
swap(x, y);
}
for(int i = 0; i < 32; i += 16){
for(int j = 0; j < (1 << 16); j++) cnt[j] = 0;
for(int j = 0; j < n; j++) ++cnt[x[j].x >> i & mask];
for(int sum = 0, j = 0; j < (1 << 16); j++){
sum += cnt[j]; cnt[j] = sum - cnt[j];
}
for(int j = 0; j < n; j++) y[cnt[x[j].x >> i & mask]++] = x[j];
swap(x, y);
}
delete[] cnt; delete[] b;
}
void main(){
radix_sort(n, tower + 1);
for(int i = 1; i <= n; i++) tx[tower[i].x].push_back(tower[i]);
for(int i = 1; i <= nx; i++) siz[i] = siz[i];
for(int i = 1; i <= nx; i++){
if(idx[i] < siz[i]){
ans[tx[i][0].id] = 1;
if(siz[i] != 1) ans[tx[i][siz[i] - 1].id] = 1;
}
}
for(int i = 1; i <= 4; i++){
from_l_to_r(1);
from_r_to_l(1);
}
from_l_to_r(0);
for(int i = 1; i <= n; i++) putchar(ans[i] + '0');
// printf("\n");
}
}
void radix_sort(int n, int a[]){
int *b = new int[n];
int *cnt = new int[1 << 16];
int mask = (1 << 16) - 1;
int *x = a, *y = b;
for(int i = 0; i < 32; i += 16){
for(int j = 0; j < (1 << 16); j++) cnt[j] = 0;
for(int j = 0; j < n; j++) ++cnt[x[j] >> i & mask];
for(int sum = 0, j = 0; j < (1 << 16); j++){
sum += cnt[j]; cnt[j] = sum - cnt[j];
}
for(int j = 0; j < n; j++) y[cnt[x[j] >> i & mask]++] = x[j];
swap(x, y);
}
delete[] cnt;
delete[] b;
}
int main(){
scanf("%d",&n);
for(int i = 1; i <= n; i++) scanf("%d%d",&tower[i].y,&tower[i].x), tower[i].id = i;
for(int i = 1; i <= n; i++) dx[i] = tower[i].x, dy[i] = tower[i].y;
radix_sort(n, dx + 1); radix_sort(n, dy + 1);
nx = unique(dx + 1, dx + n + 1) - dx - 1;
ny = unique(dy + 1, dy + n + 1) - dy - 1;
for(int i = 1; i <= n; i++) tower[i].x = lower_bound(dx + 1, dx + nx + 1, tower[i].x) - dx;
for(int i = 1; i <= n; i++) tower[i].y = lower_bound(dy + 1, dy + ny + 1, tower[i].y) - dy;
gouzao::main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 40ms
memory: 58732kb
input:
2 869400 218695 664808 31410
output:
00
result:
wrong answer
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #26:
score: 0
Wrong Answer
time: 64ms
memory: 61932kb
input:
92690 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 6...
output:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
wrong answer
Subtask #4:
score: 0
Wrong Answer
Test #38:
score: 0
Wrong Answer
time: 477ms
memory: 94980kb
input:
1000000 1 18543 4 40327 7 19084 8 44274 10 42366 12 22173 13 9862 15 44706 19 48070 21 13389 24 39273 26 18680 27 46858 28 46126 32 27753 34 28289 36 12220 38 39235 42 28505 45 47348 46 34220 48 47551 50 49156 54 8856 55 25515 56 21932 58 24482 59 20686 61 41381 66 30112 67 44504 70 24510 71 26418 7...
output:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
wrong answer
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Wrong Answer
Test #85:
score: 0
Wrong Answer
time: 555ms
memory: 102780kb
input:
1000000 1 602300 1 778881 2 397065 3 291452 3 678039 5 235300 6 499367 8 8597 10 327718 10 516489 12 416542 12 440048 13 284169 13 383581 13 642202 13 770858 14 378154 14 710033 15 905531 16 50155 17 142259 19 395613 19 500321 20 358934 21 461772 24 562953 24 995887 25 421244 27 900412 29 301006 31 ...
output:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
wrong answer