QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#1040 | #660269 | #21672. 【NOIP Round #1】冲塔 | wth2026 | max666dong123 | Failed. | 2024-10-21 20:28:17 | 2024-10-21 20:28:20 |
Details
Extra Test:
Accepted
time: 755ms
memory: 292740kb
input:
1000000 990474 235906 898562 266052 35566 936220 994115 439543 70004 308355 967649 74125 590201 862121 126357 308110 947291 33476 155274 427141 336355 66324 765958 448761 105590 608332 211124 761599 949261 955350 934341 525967 406264 107362 390469 117516 270087 886001 120645 298517 14963 49267 92853...
output:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok ok
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#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
*/