A12955 | Forced Online Queries Problem
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an undirected graph with $n$ vertices numbered from $1$ to $n$ . Initially there are no edges.
You are asked to perform some queries on the graph. Let $last$ be the answer to the latest query of the second type, it is set to $0$ before the first such query. Then the queries are the following:
- $1~x~y$ ( $1 \le x, y \le n$ , $x \ne y$ ) — add an undirected edge between the vertices $(x + last - 1)~mod~n + 1$ and $(y + last - 1)~mod~n + 1$ if it doesn't exist yet, otherwise remove it;
- $2~x~y$ ( $1 \le x, y \le n$ , $x \ne y$ ) — check if there exists a path between the vertices $(x + last - 1)~mod~n + 1$ and $(y + last - 1)~mod~n + 1$ , which goes only through currently existing edges, and set $last$ to $1$ if so and $0$ otherwise.
Good luck!
You are asked to perform some queries on the graph. Let $last$ be the answer to the latest query of the second type, it is set to $0$ before the first such query. Then the queries are the following:
- $1~x~y$ ( $1 \le x, y \le n$ , $x \ne y$ ) — add an undirected edge between the vertices $(x + last - 1)~mod~n + 1$ and $(y + last - 1)~mod~n + 1$ if it doesn't exist yet, otherwise remove it;
- $2~x~y$ ( $1 \le x, y \le n$ , $x \ne y$ ) — check if there exists a path between the vertices $(x + last - 1)~mod~n + 1$ and $(y + last - 1)~mod~n + 1$ , which goes only through currently existing edges, and set $last$ to $1$ if so and $0$ otherwise.
Good luck!
输入格式
The first line contains two integer numbers $n$ and $m$ ( $2 \le n, m \le 2 \cdot 10^5$ ) — the number of vertices and the number of queries, respectively.
Each of the following $m$ lines contains a query of one of two aforementioned types. It is guaranteed that there is at least one query of the second type.
Each of the following $m$ lines contains a query of one of two aforementioned types. It is guaranteed that there is at least one query of the second type.
输出格式
Print a string, consisting of characters '0' and '1'. The $i$ -th character should be the answer to the $i$ -th query of the second type. Therefore the length of the string should be equal to the number of queries of the second type.
输入输出样例
输入 #1
5 9 1 1 2 1 1 3 2 3 2 1 2 4 2 3 4 1 2 4 2 3 4 1 1 3 2 4 3
输出 #1
1010
输入 #2
3 9 1 1 2 1 2 3 1 3 1 2 1 3 1 3 2 2 2 3 1 1 2 2 1 2 2 1 2
输出 #2
1101
The converted queries in the first example are:
- 1 1 2
- 1 1 3
- 2 3 2
- 1 3 5
- 2 4 5
- 1 2 4
- 2 3 4
- 1 2 4
- 2 5 4
The converted queries in the second example are:
- 1 1 2
- 1 2 3
- 1 3 1
- 2 1 3
- 1 1 3
- 2 3 1
- 1 2 3
- 2 2 3
- 2 1 2
- 1 1 2
- 1 1 3
- 2 3 2
- 1 3 5
- 2 4 5
- 1 2 4
- 2 3 4
- 1 2 4
- 2 5 4
The converted queries in the second example are:
- 1 1 2
- 1 2 3
- 1 3 1
- 2 1 3
- 1 1 3
- 2 3 1
- 1 2 3
- 2 2 3
- 2 1 2
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted