CF461C.Appleman and a Sheet of Paper

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will have one of the following types:

  1. Fold the sheet of paper at position p__i. After this query the leftmost part of the paper with dimensions 1 × p__i must be above the rightmost part of the paper with dimensions 1 × ([current width of sheet] - p__i).
  2. Count what is the total width of the paper pieces, if we will make two described later cuts and consider only the pieces between the cuts. We will make one cut at distance l__i from the left border of the current sheet of paper and the other at distance r__i from the left border of the current sheet of paper.

Please look at the explanation of the first test example for better understanding of the problem.

Appleman 有一张非常大的纸。这张纸的形状是一个 1×n1 \times n 的矩形。你的任务是帮助 Appleman 完成对这张纸的折叠操作。实际上,你需要执行 qq 个查询。每个查询为以下两种类型之一:

  1. 在位置 pip_i 处将纸张对折。执行该查询后,纸张最左侧、尺寸为 1×pi1 \times p_i 的部分必须叠在最右侧、尺寸为 1×(当前纸张宽度−pi)1 \times (\text{当前纸张宽度} - p_i) 的部分之上。
  2. 计算:若在当前纸张上从左边界起距离分别为 lil_i 和 rir_i 的位置处各做一次切割(即进行下文所述的两次切割),则仅考虑两切口之间纸张片段的总宽度。

请参考第一个测试样例的解释,以更深入地理解本题。

输入格式

The first line contains two integers: n and q (1  ≤ n ≤ 105; 1 ≤ q ≤ 105) — the width of the paper and the number of queries.

Each of the following q lines contains one of the described queries in the following format:

  • "1 p__i" (1 ≤ p__i < [current width of sheet]) — the first type query.
  • "2 l__i r__i" (0 ≤ l__i < r__i ≤ [current width of sheet]) — the second type query.

第一行包含两个整数:nn 和 qq(1≤n≤1051 \leq n \leq 10^5;1≤q≤1051 \leq q \leq 10^5)—— 分别表示纸张的初始宽度和查询次数。

接下来的 qq 行中,每行包含一个如下所述类型的查询,格式如下:

  • “1 pip_i”(1≤pi<[当前纸张宽度]1 \leq p_i < [\text{当前纸张宽度}])—— 第一类查询。
  • “2 lil_i rir_i”(0≤li<ri≤[当前纸张宽度]0 \leq l_i < r_i \leq [\text{当前纸张宽度}])—— 第二类查询。

输出格式

For each query of the second type, output the answer.

对于每个第二类查询,输出答案。

输入输出样例

  • 输入#1

    7 4
    1 3
    1 2
    2 0 1
    2 1 2

    输出#1

    4
    3
  • 输入#2

    10 9
    2 2 9
    1 1
    2 0 1
    1 8
    2 0 8
    1 2
    2 1 3
    1 4
    2 2 4

    输出#2

    7
    2
    10
    4
    5

说明/提示

The pictures below show the shapes of the paper during the queries of the first example:

After the first fold operation the sheet has width equal to 4, after the second one the width of the sheet equals to 2.

下图展示了第一个示例中各次查询时纸张的形状:

第一次折叠操作后,纸张的宽度为 4;第二次折叠操作后,纸张的宽度为 2。

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

首页