CF1936B.Pinball

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is a one-dimensional grid of length nn. The ii-th cell of the grid contains a character sis_i, which is either '<' or '>'.

When a pinball is placed on one of the cells, it moves according to the following rules:

  • If the pinball is on the ii-th cell and sis_i is '<', the pinball moves one cell to the left in the next second. If sis_i is '>', it moves one cell to the right.
  • After the pinball has moved, the character sis_i is inverted (i. e. if sis_i used to be '<', it becomes '>', and vice versa).
  • The pinball stops moving when it leaves the grid: either from the left border or from the right one.

You need to answer nn independent queries. In the ii-th query, a pinball will be placed on the ii-th cell. Note that we always place a pinball on the initial grid.

For each query, calculate how many seconds it takes the pinball to leave the grid. It can be shown that the pinball will always leave the grid within a finite number of steps.

有一个长度为 nn 的一维网格。网格的第 ii 个单元格中包含一个字符 sis_i,该字符为 '<' 或 '>'。

当弹珠被放置在某个单元格上时,它将按照以下规则移动:

  • 若弹珠位于第 ii 个单元格且 sis_i 为 '<',则弹珠在下一秒向左移动一个单元格;若 sis_i 为 '>',则向右移动一个单元格。
  • 弹珠移动后,字符 sis_i 将被翻转(即若 sis_i 原为 '<',则变为 '>';反之亦然)。
  • 当弹珠离开网格(即从左边界或右边界移出)时,其运动停止。

你需要回答 nn 个相互独立的查询。在第 ii 个查询中,弹珠将被放置在第 ii 个单元格上。注意:我们始终将弹珠放置在初始网格上。

对每个查询,请计算弹珠离开网格所需的时间(以秒为单位)。可以证明,弹珠总会在有限步内离开网格。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1051 \le t \le 10^5). The description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5).

The second line of each test case contains a string s1s2…sns_1s_2 \ldots s_{n} of length nn consisting of characters '<' and '>'.

It is guaranteed that the sum of nn over all test cases does not exceed 5⋅1055 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1051 \le t \le 10^5)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤5⋅1051 \le n \le 5 \cdot 10^5)。

每个测试用例的第二行包含一个长度为 nn 的字符串 s1s2…sns_1s_2 \ldots s_{n},该字符串仅由字符 '<' 和 '>' 组成。

保证所有测试用例的 nn 之和不超过 5⋅1055 \cdot 10^5。

输出格式

For each test case, for each ii (1≤i≤n1 \le i \le n) output the answer if a pinball is initially placed on the ii-th cell.

对于每个测试用例,对每个 ii(1≤i≤n1 \le i \le n),输出当弹珠初始放置在第 ii 个格子时的答案。

输入输出样例

  • 输入#1

    3
    3
    &gt;&lt;&lt;
    4
    &lt;&lt;&lt;&lt;
    6
    &lt;&gt;&lt;&lt;&lt;&gt;

    输出#1

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

说明/提示

In the first test case, the movement of the pinball for i=1i=1 is shown in the following pictures. It takes the pinball 33 seconds to leave the grid.

The movement of the pinball for i=2i=2 is shown in the following pictures. It takes the pinball 66 seconds to leave the grid.

在第一个测试用例中,小球在 i=1i=1 时的运动过程如下图所示。小球离开网格共耗时 33 秒。

小球在 i=2i=2 时的运动过程如下图所示。小球离开网格共耗时 66 秒。

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

首页