CF566D.Restructuring Company

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Even the most successful company can go through a crisis period when you have to make a hard decision — to restructure, discard and merge departments, fire employees and do other unpleasant stuff. Let's consider the following model of a company.

There are n people working for the Large Software Company. Each person belongs to some department. Initially, each person works on his own project in his own department (thus, each company initially consists of n departments, one person in each).

However, harsh times have come to the company and the management had to hire a crisis manager who would rebuild the working process in order to boost efficiency. Let's use team(person) to represent a team where person person works. A crisis manager can make decisions of two types:

  1. Merge departments team(x) and team(y) into one large department containing all the employees of team(x) and team(y), where x and y (1 ≤ x, y ≤ n) — are numbers of two of some company employees. If team(x) matches team(y), then nothing happens.
  2. Merge departments team(x), team(x + 1), ..., team(y), where x and y (1 ≤ x ≤ y ≤ n) — the numbers of some two employees of the company.

At that the crisis manager can sometimes wonder whether employees x and y (1 ≤ x, y ≤ n) work at the same department.

Help the crisis manager and answer all of his queries.

即使是再成功的公司,也可能经历危机时期,此时必须做出艰难的决策——重组、裁撤或合并部门、裁员以及其他令人不快的措施。我们来考虑如下公司模型。

大型软件公司共有 nn 名员工。每名员工隶属于某个部门。最初,每名员工都在自己的部门中独立负责一个项目(因此,公司初始时由 nn 个部门组成,每个部门恰好一人)。

然而,公司已步入艰难时期,管理层不得不聘请一名危机经理,以重建工作流程、提升效率。我们用 team(person)\text{team}(person) 表示员工 personperson 所在的团队。危机经理可执行两类决策:

  1. 将部门 team(x)\text{team}(x) 与 team(y)\text{team}(y) 合并为一个更大的部门,该部门包含 team(x)\text{team}(x) 和 team(y)\text{team}(y) 中的所有员工,其中 xx 和 yy(1≤x,y≤n1 \le x, y \le n)是公司中两名员工的编号。若 team(x)\text{team}(x) 与 team(y)\text{team}(y) 相同,则不发生任何变化。
  2. 将部门 team(x), team(x+1), …, team(y)\text{team}(x),\ \text{team}(x+1),\ \dots,\ \text{team}(y) 合并,其中 xx 和 yy(1≤x≤y≤n1 \le x \le y \le n)是公司中两名员工的编号。

在此过程中,危机经理有时会想知道员工 xx 和 yy(1≤x,y≤n1 \le x, y \le n)是否在同一部门工作。

请协助危机经理,回答其所有查询。

输入格式

The first line of the input contains two integers n and q (1 ≤ n ≤ 200 000, 1 ≤ q ≤ 500 000) — the number of the employees of the company and the number of queries the crisis manager has.

Next q lines contain the queries of the crisis manager. Each query looks like type x y, where . If type = 1 or type = 2, then the query represents the decision of a crisis manager about merging departments of the first and second types respectively. If type = 3, then your task is to determine whether employees x and y work at the same department. Note that x can be equal to y in the query of any type.

输入的第一行包含两个整数 nn 和 qq(1≤n≤200 0001 \leq n \leq 200\,000,1≤q≤500 0001 \leq q \leq 500\,000),分别表示公司员工人数以及危机经理提出的查询次数。

接下来的 qq 行为危机经理的查询,每行形如 type x y,其中 。若 type = 1 或 type = 2,则该查询表示危机经理分别就第一类或第二类部门作出合并决策;若 type = 3,则你需要判断员工 xx 和 yy 是否在同一部门工作。注意:在任意类型的查询中,xx 可能等于 yy。

输出格式

For each question of type 3 print "YES" or "NO" (without the quotes), depending on whether the corresponding people work in the same department.

对于每个类型为 3 的查询,根据对应人员是否在同一部门工作,输出 “YES” 或 “NO”(不带引号)。

输入输出样例

  • 输入#1

    8 6
    3 2 5
    1 2 5
    3 2 5
    2 4 7
    2 1 2
    3 1 7

    输出#1

    NO
    YES
    YES

输入解题思路,AI测评打分。不知道怎么写?

首页