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>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, l = 0, r = 0; cin >>n >> m;
vector<ii> v[n+1];
set<ii> st;
rep (i,1,m) {
int a, b; cin >> a >> b;
v[a].pb({b,i});
}
bool suc = 1, ans[m+1] = {};
rep (i,1,n) {
for (ii bi : v[i]) st.insert(bi);
if (l<i) {
if (st.size() && (*st.rbegin()).fi>=i) {
l = (*st.rbegin()).fi;
st.erase(--st.end());
}
else {
suc = 0;
break;
}
}
if (r<i) {
if (st.size() && (*st.rbegin()).fi>=i) {
ans[(*st.rbegin()).se] = 1;
r = (*st.rbegin()).fi;
st.erase(--st.end());
}
else {
suc = 0;
break;
}
}
}
if (!suc) cout << "impossible\n";
else {
rep (i,1,m) cout << ans[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... |