luogu#P4794. [BalticOI 2018] 交流电

    ID: 3818 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心2018Special Judge枚举排序BalticOI(波罗的海)

[BalticOI 2018] 交流电

Background

Abusing the judge for this problem will result in your account being banned.

Problem Description

This problem is translated from BalticOI 2018 Day 2 “Alternating Current”.

You are given a circular track, which can be divided into NN equal-length segments, numbered 1N1 \ldots N. At the same time, you have MM control points that can color certain segments of the track either red or blue. These MM control points are numbered 1M1 \ldots M.

Your task is to choose the colors of the segments controlled by these MM points so that every point on the track is covered by at least one red segment and at least one blue segment.

It is guaranteed that there is no part of the circle that cannot be colored.

Input Format

The first line contains two integers NN and MM, representing the number of track segments and the number of control points.

The next MM lines each contain two integers aa and bb, representing the left and right endpoints of the range that the control point can color. In particular, if a=ba=b, then this control point only controls the single segment aa with length 11; if b<ab < a, then this control point can control all segments with indices in the interval [a,N][1,b][a,\, N]\cup[1,\,b].

Output Format

Output one line containing MM characters. Each character is either 0 or 1, indicating whether the segment controlled by the ii-th control point is colored red or blue.

If there are multiple solutions, output any one of them. If there is no solution, output impossible.

10 5
1 5
6 7
5 1
7 2
2 4
00101


10 5
1 4
2 5
4 7
6 10
8 1
impossible
5 2
1 5
3 3
impossible
5 3
3 3
2 1
4 2
101


Hint

Explanation for Sample 1

The figure above shows one solution for Sample 1. Note that you can reverse all arrows to obtain another valid solution 11010.

Constraints

Subtask Score Constraints Additional Constraints
11 1313 2N,M152\leqslant N,\,M\leqslant15 .
22 2020 2N,M1002\leqslant N,\,M\leqslant100
33 2222 2N,M10002\leqslant N,\,M\leqslant1000
44 1919 2N,M1000002\leqslant N,\,M\leqslant100\,000 It is guaranteed that bab\geqslant a.
55 2626

Thanks to Hatsune_Miku for providing the translation.

Input Format

Output Format

Hint

Translated by ChatGPT 5