QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#42. 交流电

Statistics

Fredrik 正在家里玩他引以为傲的自制模型铁路。铁路包含 $N$ 个首尾相连的轨道段,按顺时针方向编号为 $1, 2, \dots, N$。电力通过 $M$ 条沿圆环铺设的弧形导线提供。每个轨道段至少有一条导线经过。

然而,Fredrik 对他那只会绕圈的火车感到厌倦,于是决定在每个轨道段上都加装一个道岔,他可以用它来制造脱轨事故和其他令人兴奋的场景。但这些道岔也需要电力。而且不仅仅是普通的电力;它们特别需要交流电。

Fredrik 认为,获得交流电的方法是让电流双向流动。每条导线只能提供单一方向的电流(顺时针或逆时针),但 Fredrik 可以自由决定每条导线的方向。因此,他想要为每条导线的电流方向做出决定,使得每个轨道段既被一条顺时针电流的导线覆盖,也被一条逆时针电流的导线覆盖。

你能帮助 Fredrik 完成这项任务吗?

第一个样例的一种解法。铁路外侧的弧形箭头代表提供电力的导线。每个箭头的方向代表 Fredrik 对电流方向的选择(蓝色和红色分别强调了不同的方向)。注意,所有箭头都可以反转以得到另一个有效解:11010。

输入格式

第一行包含两个整数 $N$ 和 $M$,分别表示轨道段的数量和导线的数量。

接下来的 $M$ 行,每行包含两个数字 $1 \le a, b \le N$,表示有一条导线覆盖了轨道段 $a, a+1, \dots, b$。如果 $b$ 小于 $a$,则表示该序列跨越了圆环的起点,即覆盖了轨道段 $a, \dots, N, 1, \dots, b$。注意,如果 $a = b$,则该导线仅覆盖一个轨道段。

输出格式

输出一行包含 $M$ 个字符,每个字符为 0 或 1。如果输入中第 $i$ 条导线的电流应为顺时针方向,则第 $i$ 个字符应为 0;如果应为逆时针方向,则应为 1。如果存在多个解,你可以输出其中任意一个。

如果不存在有效解,输出 “impossible”。

数据范围

你的解法将在若干测试组上进行测试,每组测试包含若干测试点。要获得某一组的分数,你需要通过该组内的所有测试点。最终得分为单次提交的最高得分。

组别 分数 数据范围 附加限制
1 13 $2 \le N, M \le 15$
2 20 $2 \le N, M \le 100$
3 22 $2 \le N, M \le 1000$
4 19 $2 \le N, M \le 100\,000$ 无导线满足 $b < a$
5 26 $2 \le N, M \le 100\,000$

样例

样例输入 1

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

样例输出 1

00101

样例输入 2

10 5
1 4
2 5
4 7
6 10
8 1

样例输出 2

impossible

样例输入 3

5 2
1 5
3 3

样例输出 3

impossible

样例输入 4

5 3
3 3
2 1
4 2

样例输出 4

101

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.