Logo
(追記) (追記ここまで)

34605번 - Tower of Hanoi 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB13121191.667%

문제

While visiting Hanoi to compete in The ICPC Asia Pacific Championship last year, you learned about the famous Tower of Hanoi problem. In the problem, there are three rods and several disks of distinct radii, which can slide onto any rod. The rods are numbered from 1ドル$ to 3ドル$. At any point in time, each disk must be stacked on one of the rods, and the disks stacked on each rod must be arranged in increasing order of radius from top to bottom. In one step, you can move the disk on top of one rod to the top of another rod, provided this move does not violate the restriction above. The goal is to move all the disks to rod 1ドル$ in the minimum number of steps.

You are solving an extension of this famous problem. You have a sequence of $n$ integers $p_1, p_2, \dots , p_n,ドル the initial values of which are given to you.

You are also given $q$ operations. Each operation is either of the following:

Change operation: Two integers $x$ and $y$ are given. This operation requires you to change the value of $p_x$ to $y$.

Solve operation: Two integers $l$ and $r$ are given. This operation requires you to solve the Tower of Hanoi problem with $r − l + 1$ disks of radii $l, l + 1, \dots , r,ドル where the disk of radius $i$ is initially stacked on rod $p_i,ドル for each $l ≤ i ≤ r$. The order of the disks initially stacked on each rod satisfies the restriction explained earlier. You need to find the minimum number of steps to move all disks to rod 1ドル$ modulo 998ドル,円 244,円 353$.

Your task is to perform all the given operations sequentially.

입력

The first line of input contains two integers $n$ and $q$ (1ドル ≤ n ≤ 100,円 000$; 1ドル ≤ q ≤ 100,円 000$). The second line contains $n$ integers representing the initial values of $p_1, p_2, \dots , p_n$ (1ドル ≤ p_i ≤ 3$). The next $q$ lines represent the operations in the order they are to be performed. Each line is in one of the following formats:

  1. “$c$ $x$ $y$” (1ドル ≤ x ≤ n$; 1ドル ≤ y ≤ 3$) to apply a Change operation for the specified integers $x$ and $y$.
  2. “$s$ $l$ $r$” (1ドル ≤ l ≤ r ≤ n$) to apply a Solve operation for the specified integers $l$ and $r$.

The input contains at least one Solve operation.

출력

For each Solve operation, in order, output the minimum number of steps to solve the Tower of Hanoi problem with disks of radii $l, l + 1, \dots , r$ modulo 998ドル,円 244,円 353$.

제한

예제 입력 1

4 4
2 3 1 3
s 2 4
s 1 3
c 3 3
s 2 4

예제 출력 1

6
2
7

The first operation requires you to solve the Tower of Hanoi problem with disks of radii 2ドル,ドル 3ドル,ドル and 4ドル$ initially stacked on rods 3ドル,ドル 1ドル,ドル and 3ドル$ respectively. All disks can be moved to rod 1ドル$ in 6ドル$ steps as illustrated by Figure D.1.

Figure D.1: 6ドル$ steps to move all disks to rod 1ドル$. The shaded rod represents the rod moved on the last step.

The second operation requires you to solve the Tower of Hanoi problem with disks of radii 1ドル,ドル 2ドル,ドル and 3ドル$ initially stacked on rods 2ドル,ドル 3ドル,ドル and 1ドル$ respectively.

The fourth operation requires you to solve the Tower of Hanoi problem with disks of radii 2ドル,ドル 3ドル,ドル and 4ドル$ initially stacked on rods 3ドル,ドル 3ドル,ドル and 3ドル$ respectively.

노트

출처

ICPC > Regionals > Asia Pacific > Asia Pacific Championship > The 2025 ICPC Asia Pacific Championship D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /