CF1217F.Forced Online Queries Problem

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an undirected graph with nn vertices numbered from 11 to nn . Initially there are no edges.

You are asked to perform some queries on the graph. Let lastlast be the answer to the latest query of the second type, it is set to 00 before the first such query. Then the queries are the following:

  • 1 x y1~x~y ( 1x,yn1 \le x, y \le n , xyx \ne y ) — add an undirected edge between the vertices (x+last1) mod n+1(x + last - 1)~mod~n + 1 and (y+last1) mod n+1(y + last - 1)~mod~n + 1 if it doesn't exist yet, otherwise remove it;
  • 2 x y2~x~y ( 1x,yn1 \le x, y \le n , xyx \ne y ) — check if there exists a path between the vertices (x+last1) mod n+1(x + last - 1)~mod~n + 1 and (y+last1) mod n+1(y + last - 1)~mod~n + 1 , which goes only through currently existing edges, and set lastlast to 11 if so and 00 otherwise.

Good luck!

输入格式

The first line contains two integer numbers nn and mm ( 2n,m21052 \le n, m \le 2 \cdot 10^5 ) — the number of vertices and the number of queries, respectively.

Each of the following mm 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 ii -th character should be the answer to the ii -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
首页