#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n,m; cin >> n >> m;
vector<pair<pair<int,int>,int>> edge1(m);
vector<pair<int,int>> edge(m);
vector<bool> c(m);
vector<pair<int,int>> furthest(n+1, {-1,-1});
for (int i = 0; i < m; i++)
{
int a,b; cin >> a >> b;
edge1[i]={{a,b},i};
}
sort(all(edge1));
for (int i = 0; i < m; i++)
{
edge[i]={edge1[i].first.first,edge1[i].first.second};
}
priority_queue<pair<int,int>> pq;
int j=0;
for (int i = 0; i <= n; i++)
{
while(j<sz(edge)&&edge[j].first-1<=i){
pq.push({edge[j].second,j});
j++;
}
while(!pq.empty()&&pq.top().first<=i){
pq.pop();
}
if(!pq.empty()) furthest[i]=pq.top();
}
int e=0;
while(e!=n){
if(furthest[e].first==-1) break;
c[edge1[furthest[e].second].second]=1;
e=furthest[e].first;
}
bool b=(e==n);
e=0;
for (int i = 0; i < m; i++)
{
if(c[edge1[i].second]==1) continue;
if(e>=edge[i].first-1) e=edge[i].second;
}
b=(e==n);
if(b==false) cout << "impossible\n";
else{
for (int i = 0; i < m; i++)
{
cout << c[i];
}
cout << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |