QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56927 | #3873. Towers | Janus | Compile Error | / | / | C++ | 6.3kb | 2022-10-21 21:58:50 | 2022-10-21 21:59:25 |
Judging History
This is the latest submission verdict.
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2022-10-21 21:59:25]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2022-10-21 21:58:50]
- Submitted
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 坐标的集合
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] = tx[i].size() - 1;
// for(int i = ny; i >= 1; i--){
// if(cy[i].empty()) continue;
// idx[cy[i].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){
// cy[tx[now][idx[now]].y].push(now);
// ans[tx[now][idx[now]].id] = 1;
// }
// }
// if(!cy[i].empty()){
// idx[cy[i].top()]--;
// cy[i].pop();
// }
// }
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] = tx[i].size();
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
answer.code: In function ‘void gouzao::from_r_to_l(int)’: answer.code:47:34: error: ‘q’ was not declared in this scope 47 | if(cy[i].size() > 2) q.push(i); | ^ answer.code:49:16: error: ‘q’ was not declared in this scope 49 | while(!q.empty()){ | ^ answer.code: In function ‘int main()’: answer.code:150:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 150 | scanf("%d",&n); | ~~~~~^~~~~~~~~ answer.code:151:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 151 | for(int i = 1; i <= n; i++) scanf("%d%d",&tower[i].y,&tower[i].x), tower[i].id = i; | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~