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;
typedef long long ll;
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn5 = 2e5 + 10;
int a[maxn5], b[maxn5];
bool av[2][maxn5];
int n, m;
bool ty[maxn5];
vector <int> seg[maxn5], ex;
inline void kill(){
cout << "impossible" << endl;
exit(0);
}
inline void solve(){
for(int i = 0; i < m; i++){
seg[a[i]].pb(i);
}
int id1 = -1, id2 = -1;
for(int i = 0; i < n; i++){
if(b[id1] < i)
id1 = -1;
if(b[id2] < i)
id2 = -1;
while(!ex.empty() && b[ex.back()] < i)
ex.pop_back();
for(auto u : seg[i])
ex.pb(u);
if(id1 == -1){
if(ex.empty())
kill();
id1 = ex.back();
ty[id1] = true;
ex.pop_back();
}
while(!ex.empty() && b[ex.back()] < i)
ex.pop_back();
if(id2 == -1){
if(ex.empty())
kill();
id2 = ex.back();
ex.pop_back();
}
}
for(int i = 0; i < m; i++)
cout << ty[i];
cout << endl;
exit(0);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
}
if(max(n, m) > 20)
solve();
for(int mask = 1; mask < (1 << m) - 1; mask++){
memset(av, false, sizeof av);
for(int i = 0; i < m; i++){
int x = a[i];
while(true){
av[(mask >> i)&1][x] = true;
if(x == b[i])
break;
x++;
if(x == n)
x = 0;
}
}
bool re = true;
for(int i = 0; i < n; i++)
if(!av[0][i] || !av[1][i])
re = false;
if(re){
for(int i = 0; i < m; i++)
cout << ((mask >> i)&1);
return cout << endl, 0;
}
}
cout << "impossible" << endl;
}
# | 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... |