Submission #27696901
Source Code Expand
/**
* author: gary
* created: 04.12.2021 19:52:07
**/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define rep(a,b) for(int a=0;a<b;++a)
#define LL long long
#define PB push_back
#define POB pop_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
int fa[1000000+20];
int root(int x){
return fa[x]=(fa[x]==x? x:root(fa[x]));
}
int id[1000000+20];
vector<int> v[1000000+20];
int pre[1000000+20];
bool vis[1000000+20];
int mn[1000000+20];
int main(){
// freopen("c.in","r",stdin);
// freopen("c.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
rb(i,0,n) fa[i]=i;
vector<mp> seg;
int m;
cin>>m;
rb(i,1,m){
int l,r;
cin>>l>>r;
int A,B;
A=root(r);
B=root(l-1);
fa[max(A,B)]=min(A,B);
}
rb(i,0,n) mn[i]=INF;
rb(i,0,n) check_min(mn[root(i)],i);
rb(i,0,n) id[i]=mn[root(i)],v[id[i]].PB(i);
int tmp=0;
set<int> se;
for(int i=0;tmp!=n+1;i--){
if(i==0){
tmp+=v[0].size();
for(auto it:v[0]){
vis[it]=1;
se.insert(it);
pre[it]=0;
}
assert(!se.empty());
continue;
}
set<int> nw;
for(auto ite=se.begin();ite!=se.end();ite++){
if(*ite!=0&&!vis[*ite-1]){
nw.insert(id[*ite-1]);
}
if(*ite!=n&&!vis[*ite+1]){
nw.insert(id[*ite+1]);
}
}
assert(!nw.empty());
se.clear();
for(auto ite=nw.begin();ite!=nw.end();ite++){
auto Tmp=v[*ite];
tmp+=Tmp.size();
for(auto it:Tmp){
vis[it]=1;
se.insert(it);
pre[it]=i;
}
}
}
rb(i,1,n){
if(pre[i]==pre[i-1]-1) cout<<0;
else cout<<1;
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
C - 01 Balanced |
| User |
Gary |
| Language |
C++ (GCC 9.2.1) |
| Score |
900 |
| Code Size |
2365 Byte |
| Status |
AC |
| Exec Time |
899 ms |
| Memory |
87772 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
900 / 900 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt |
| All |
00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00-sample-001.txt |
AC |
23 ms |
26932 KiB |
| 00-sample-002.txt |
AC |
30 ms |
26932 KiB |
| 00-sample-003.txt |
AC |
24 ms |
26932 KiB |
| 01-001.txt |
AC |
23 ms |
27028 KiB |
| 01-002.txt |
AC |
561 ms |
71500 KiB |
| 01-003.txt |
AC |
453 ms |
61472 KiB |
| 01-004.txt |
AC |
72 ms |
31976 KiB |
| 01-005.txt |
AC |
436 ms |
59704 KiB |
| 01-006.txt |
AC |
469 ms |
60920 KiB |
| 01-007.txt |
AC |
878 ms |
84812 KiB |
| 01-008.txt |
AC |
887 ms |
84876 KiB |
| 01-009.txt |
AC |
883 ms |
84760 KiB |
| 01-010.txt |
AC |
899 ms |
84812 KiB |
| 01-011.txt |
AC |
868 ms |
84828 KiB |
| 01-012.txt |
AC |
872 ms |
84764 KiB |
| 01-013.txt |
AC |
890 ms |
84608 KiB |
| 01-014.txt |
AC |
873 ms |
84504 KiB |
| 01-015.txt |
AC |
871 ms |
84596 KiB |
| 01-016.txt |
AC |
880 ms |
84848 KiB |
| 01-017.txt |
AC |
232 ms |
68696 KiB |
| 01-018.txt |
AC |
229 ms |
68596 KiB |
| 01-019.txt |
AC |
232 ms |
68600 KiB |
| 01-020.txt |
AC |
235 ms |
68528 KiB |
| 01-021.txt |
AC |
230 ms |
68608 KiB |
| 01-022.txt |
AC |
236 ms |
68600 KiB |
| 01-023.txt |
AC |
234 ms |
68624 KiB |
| 01-024.txt |
AC |
235 ms |
68644 KiB |
| 01-025.txt |
AC |
231 ms |
68528 KiB |
| 01-026.txt |
AC |
236 ms |
68696 KiB |
| 01-027.txt |
AC |
340 ms |
87720 KiB |
| 01-028.txt |
AC |
336 ms |
87772 KiB |
| 01-029.txt |
AC |
209 ms |
68528 KiB |