CF1371F.Raging Thunder

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are a warrior fighting against the machine god Thor.

Thor challenge you to solve the following problem:

There are nn conveyors arranged in a line numbered with integers from 11 to nn from left to right. Each conveyor has a symbol "<" or ">". The initial state of the conveyor ii is equal to the ii-th character of the string ss. There are n+1n+1 holes numbered with integers from 00 to nn. The hole 00 is on the left side of the conveyor 11, and for all i≥1i \geq 1 the hole ii is on the right side of the conveyor ii.

When a ball is on the conveyor ii, the ball moves by the next rules:

If the symbol "<" is on the conveyor ii, then:

  • If i=1i=1, the ball falls into the hole 00.
  • If the symbol "<" is on the conveyor i−1i-1, the ball moves to the conveyor i−1i-1.
  • If the symbol ">" is on the conveyor i−1i-1, the ball falls into the hole i−1i-1.

If the symbol ">" is on the conveyor ii, then:

  • If i=ni=n, the ball falls into the hole nn.
  • If the symbol ">" is on the conveyor i+1i+1, the ball moves to the conveyor i+1i+1.
  • If the symbol "<" is on the conveyor i+1i+1, the ball falls into the hole ii.

You should answer next qq queries, each query is defined by the pair of integers l,rl, r (1≤l≤r≤n1 \leq l \leq r \leq n):

  • First, for all conveyors l,l+1,...,rl,l+1,...,r, the symbol "<" changes to ">" and vice versa. These changes remain for the next queries.
  • After that, put one ball on each conveyor l,l+1,...,rl,l+1,...,r. Then, each ball falls into some hole. Find the maximum number of balls in one hole. After the query all balls disappear and don't considered in the next queries.

你是一名战士,正在与机器之神索尔作战。

索尔向你发起如下挑战:

有 nn 条传送带从左到右依次排列,编号为 11 到 nn。每条传送带上有一个符号 "<" 或 ">"。传送带 ii 的初始状态等于字符串 ss 的第 ii 个字符。共有 n+1n+1 个洞,编号为 00 到 nn。洞 00 位于传送带 11 的左侧;对所有 i≥1i \geq 1,洞 ii 位于传送带 ii 的右侧。

当一个球位于传送带 ii 上时,它按如下规则移动:

若传送带 ii 上的符号为 "<",则:

  • 若 i=1i = 1,球落入洞 00;
  • 若传送带 i−1i-1 上的符号为 "<",球移至传送带 i−1i-1;
  • 若传送带 i−1i-1 上的符号为 ">",球落入洞 i−1i-1。

若传送带 ii 上的符号为 ">",则:

  • 若 i=ni = n,球落入洞 nn;
  • 若传送带 i+1i+1 上的符号为 ">",球移至传送带 i+1i+1;
  • 若传送带 i+1i+1 上的符号为 "<",球落入洞 ii。

你需要回答接下来的 qq 个查询,每个查询由一对整数 l,rl, r(满足 1≤l≤r≤n1 \leq l \leq r \leq n)定义:

  • 首先,对所有传送带 l,l+1,…,rl, l+1, \dots, r,将符号 "<" 变为 ">",">" 变为 "<"。这些更改在后续查询中持续生效。
  • 然后,在每条传送带 l,l+1,…,rl, l+1, \dots, r 上各放置一个球。随后,每个球均会落入某个洞中。求所有洞中球数的最大值。查询结束后,所有球消失,不参与后续查询。

输入格式

The first line contains two integers nn, qq (1≤n≤5×105,1≤q≤1051 \le n \le 5 \times 10^5 , 1 \le q \le 10^5).

The second line contains a string ss of length nn. It consists of characters "<" and ">".

Next qq lines contain the descriptions of the queries, ii-th of them contains two integers ll, rr (1≤l≤r≤n)(1 \le l \le r \le n), describing the ii-th query.

第一行包含两个整数 nn、qq(1≤n≤5×1051 \le n \le 5 \times 10^5,1≤q≤1051 \le q \le 10^5)。

第二行包含一个长度为 nn 的字符串 ss,它仅由字符 "<" 和 ">" 组成。

接下来 qq 行,每行描述一个查询;其中第 ii 行包含两个整数 ll、rr(1≤l≤r≤n1 \le l \le r \le n),表示第 ii 个查询。

输出格式

Print qq lines, in the ii-th of them print the answer to the ii-th query.

输出 qq 行,其中第 ii 行输出第 ii 个查询的答案。

输入输出样例

  • 输入#1

    5 6
    &gt;&lt;&gt;&gt;&lt;
    2 4
    3 5
    1 5
    1 3
    2 4
    1 5

    输出#1

    3
    3
    5
    3
    2
    3

说明/提示

  • In the first query, the conveyors change to ">><<<". After that, put a ball on each conveyor 2,3,4{2,3,4}. All three balls fall into the hole 22. So the answer is 33.

  • In the second query, the conveyors change to ">>>>>". After that, put a ball on each conveyor 3,4,5{3,4,5}. All three balls fall into the hole 55. So the answer is 33.

  • In the third query, the conveyors change to "<<<<<". After that, put a ball on each conveyor 1,2,3,4,5{1,2,3,4,5}. All five balls fall into the hole 00. So the answer is 55.

  • In the fourth query, the conveyors change to ">>><<". After that, put a ball on each conveyor 1,2,3{1,2,3}. All three balls fall into the hole 33. So the answer is 33.

  • In the fifth query, the conveyors change to "><<><". After that, put a ball on each conveyor 2,3,4{2,3,4}. Two balls fall into the hole 11, and one ball falls into the hole 44. So, the answer is 22.

  • In the sixth query, the conveyors change to "<>><>". After that, put a ball on each conveyor 1,2,3,4,5{1,2,3,4,5}. Three balls fall into the hole 33, one ball falls into the hole 00 and one ball falls into the hole 55. So, the answer is 33.

  • 在第一次查询中,传送带变为“>><<<”。之后,在传送带 {2,3,4}\{2,3,4\} 上各放置一个球。这三个球全部落入洞 22。因此答案为 33。

  • 在第二次查询中,传送带变为“>>>>>”。之后,在传送带 {3,4,5}\{3,4,5\} 上各放置一个球。这三个球全部落入洞 55。因此答案为 33。

  • 在第三次查询中,传送带变为 “<<<<<<”。之后,在传送带 {1,2,3,4,5}\{1,2,3,4,5\} 上各放置一个球。这五个球全部落入洞 00。因此答案为 55。

  • 在第四次查询中,传送带变为 “>>><<”。之后,在传送带 {1,2,3}\{1,2,3\} 上各放置一个球。这三个球全部落入洞 33。因此答案为 33。

  • 在第五次查询中,传送带变为 “><<><”。之后,在传送带 {2,3,4}\{2,3,4\} 上各放置一个球。其中两个球落入洞 11,一个球落入洞 44。因此答案为 22。

  • 在第六次查询中,传送带变为 “<>><>”。之后,在传送带 {1,2,3,4,5}\{1,2,3,4,5\} 上各放置一个球。其中三个球落入洞 33,一个球落入洞 00,一个球落入洞 55。因此答案为 33。

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

首页