This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;
typedef long long ll;
struct Info{
int s, e, x;
Info() : Info(0, 0, 0) {}
Info(int s, int e, int x) : s(s), e(e), x(x) {}
bool operator < (const Info &t) const {
if(s != t.s) return s < t.s;
if(e != t.e) return e > t.e;
return x < t.x;
}
};
int n, m;
Info a[101010];
int ans[101010];
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for(int i=1; i<=m; i++){ cin >> a[i].s >> a[i].e; a[i].x = i; }
sort(a+1, a+m+1);
int cnt0 = 0, cnt1 = 0;
for(int i=1; i<=m; i++){
int s = a[i].s, e = a[i].e, x = a[i].x;
if(cnt0 < cnt1){
if(cnt0 >= s-1) cnt0 = max(cnt0, e), ans[x] = 0;
}else{
if(cnt1 >= s-1) cnt1 = max(cnt1, e), ans[x] = 1;
}
}
if(cnt0 < n || cnt1 < n){
cout << "impossible"; return 0;
}
for(int i=1; i<=m; i++) cout << ans[i] << " ";
}
# | 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... |