QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#1037 | #660269 | #21672. 【NOIP Round #1】冲塔 | wth2026 | max666dong123 | Failed. | 2024-10-21 20:17:33 | 2024-10-21 20:17:33 |
详细
Extra Test:
Accepted
time: 819ms
memory: 290964kb
input:
1000000 150331 727168 298281 270877 540458 931404 842075 145541 116273 363073 139023 736558 838844 241399 48649 600086 553056 240368 829903 677100 885541 684183 649182 8613 808643 394992 619771 406630 486952 773754 246969 643986 386069 67564 491879 393821 476943 370290 473138 498386 999947 282117 23...
output:
000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok ok
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#660269 | #21672. 【NOIP Round #1】冲塔 | max666dong123 | 100 ✓ | 2091ms | 405772kb | C++14 | 5.5kb | 2024-10-20 09:51:57 | 2024-10-20 09:51:58 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e6+10;
namespace TEST3{
const int N=2e6+10;
int n;
struct node{
int x,y;
int i;
}a[N];
map<int,int>mp;
vector<int>b;
int idx;
struct NODE{
int y;
int i;
};
list<NODE>row[N];
int line[N][2];
int len[N];
bool ans[N];
void del(int r,int pos){
if(pos==1){
len[row[r].front().y]--;
row[r].pop_front();
}
else{
len[row[r].back().y]--;
row[r].pop_back();
}
if(row[r].size()<=1){
return;
}
list<NODE>::iterator it;
if(pos==1){
it=row[r].begin();
}
else{
it=row[r].end();it=next(it,-1);
}
if(len[it->y]<=1){
line[it->y][++len[it->y]]=r;
}
else{
int pos=1;
if(row[line[it->y][2]].front().y==it->y){
}
else{
pos=2;
}
del(line[it->y][2],pos);
line[it->y][++len[it->y]]=r;
}
}
bool cmp(node x,node y){
return x.x<y.x||(x.x==y.x&&x.y<y.y);
}
signed main(){
// freopen("tower.in","r",stdin);
// freopen("tower.out","w",stdout);
// scanf("%lld",&n);
for(int i=1;i<=n;i++){
// scanf("%lld%lld",&a[i].x,&a[i].y);
b.push_back(a[i].x);
b.push_back(a[i].y);
a[i].i=i;
}
sort(b.begin(),b.end());
for(int x:b){
if(mp[x]){
continue;
}
mp[x]=++idx;
}
for(int i=1;i<=n;i++){
a[i].x=mp[a[i].x];
a[i].y=mp[a[i].y];
// cout<<a[i].y<<" "<<i<<endl;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++){
row[a[i].x].push_back({a[i].y,a[i].i});
}
for(int i=1;i<=idx;i++){
if(row[i].size()<=0){
continue;
}
list<NODE>::iterator it=row[i].begin();
if(len[it->y]<=1){
line[it->y][++len[it->y]]=i;
}
else{
int pos=1;
if(row[line[it->y][2]].front().y==it->y){
}
else{
pos=2;
}
del(line[it->y][2],pos);
line[it->y][++len[it->y]]=i;
}
if(row[i].size()<=1){
continue;
}
it=row[i].end();it=next(it,-1);
if(len[it->y]<=1){
line[it->y][++len[it->y]]=i;
}
else{
int pos=1;
if(row[line[it->y][2]].front().y==it->y){
}
else{
pos=2;
}
del(line[it->y][2],pos);
line[it->y][++len[it->y]]=i;
}
}
for(int i=1;i<=idx;i++){
if(row[i].size()<=0){
continue;
}
ans[row[i].front().i]=1;
ans[row[i].back().i]=1;
}
for(int i=1;i<=n;i++){
cout<<ans[i];
}
return 0;
}
}
int n;
struct node{
int x,y;
int i;
}a[N];
map<int,int>mp;
int fmp[N];
vector<int>b;
int idx;
struct NODE{
int y;
int i;
};
list<NODE>row[N];
set<int>line[N];
int ans[N];
bool cmp(node x,node y){
return (x.x<y.x)||(x.x==y.x&&x.y<y.y)||(x.x==y.x&&x.y==y.y&&x.i<y.i);
}
signed main(){
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld%lld",&a[i].x,&a[i].y);
b.push_back(a[i].x);
b.push_back(a[i].y);
a[i].i=i;
}
int maxx=0;
int maxy=0;
for(int i=1;i<=n;i++){
maxx=max(maxx,a[i].x);
maxy=max(maxy,a[i].y);
}
if(maxx*maxy==n){
// cout<<"YES\n";
TEST3::n=n;
for(int i=1;i<=n;i++){
TEST3::a[i].i=a[i].i;
TEST3::a[i].x=a[i].x;
TEST3::a[i].y=a[i].y;
}
TEST3::main();
return 0;
}
sort(b.begin(),b.end());
for(int x:b){
if(mp[x]){
continue;
}
mp[x]=++idx;
fmp[idx]=x;
}
for(int i=1;i<=n;i++){
a[i].x=mp[a[i].x];
a[i].y=mp[a[i].y];
// cout<<a[i].x<<" "<<a[i].y<<endl;
}
sort(a+1,a+1+n,cmp);
int min1=LONG_LONG_MAX;
for(int i=1;i<=n;i++){
row[a[i].x].push_back({a[i].y,a[i].i});
// min1=min(min1,a[i].y);
}
for(int i=1;i<=idx;i++){
if(row[i].size()<=0){
continue;
}
min1=min(min1,row[i].front().y);
}
for(int i=1;i<=idx;i++){
if(row[i].size()<=0){
continue;
}
list<NODE>::iterator it=row[i].begin();
line[it->y].insert(i);
if(row[i].size()<=1){
continue;
}
it=row[i].end();it=next(it,-1);
line[it->y].insert(i);
}
while(1){
int cnt=0;
for(int i=idx;i>=1;i--){
// if(i==min1){
// if(line[i].size()<=2){
// break;
// }
// for(set<int>::iterator it=next(line[i].begin(),1);it!=next(line[i].end(),-1);it++){
// row[*it].pop_front();
//// cout<<i<<" "<<" - "<<(*it)<<endl;
//// if(row[*it].size()>=2){
//// line[row[*it].back().y].insert(*it);
//// }
// }
// break;
// }
vector<int>er;
if(line[i].size()>2){
// cout<<j<<" "<<line[i].size()<<endl;
for(set<int>::iterator it=next(line[i].begin(),1);it!=next(line[i].end(),-1);it++){
er.push_back(*it);
if(row[*it].back().y==i){
row[*it].pop_back();
if(row[*it].size()>=2){
line[row[*it].back().y].insert(*it);
cnt++;
}
}
else{
row[*it].pop_front();
if(row[*it].size()>=2){
line[row[*it].front().y].insert(*it);
cnt++;
}
}
// cout<<i<<" "<<" - "<<(*it)<<endl;
}
// len[i]=2;
}
for(int x:er){
line[i].erase(x);
}
}
if(!cnt){
break;
}
}
for(int i=1;i<=idx;i++){
if(row[i].size()<=0){
continue;
}
ans[row[i].front().i]=1;
ans[row[i].back().i]=1;
}
for(int i=1;i<=idx;i++){
if(row[i].size()<=0){
continue;
}
// cout<<i<<" "<<row[i].front().y<<" A"<<endl;
// cout<<i<<" "<<row[i].back().y<<" A"<<endl;
// ans[row[i].front().i]=1;
// ans[row[i].back().i]=1;
}
// cout<<len[1]<<endl;
for(int i=1;i<=n;i++){
// cout<<ans[i];
printf("%lld",ans[i]);
}
return 0;
}
/*
11
4 2
1 2
1 1
3 3
2 1
4 1
2 3
2 4
1 4
4 3
3 4
*/