TopCoder

User's AC Ratio

100.0% (3/3)

Submission's AC Ratio

55.6% (5/9)

Tags

Description

考慮以下定義在正整數上的函數:
$$
\mathrm{collatz}(n)=
\begin{cases}
3n+1 &\text{if }n\text{ is odd,}\\
n/2 &\text{otherwise.}
\end{cases}
$$

1937 年,Lothar Collatz 提出了一個猜想:對於任何正整數,重複代入 $\mathrm{collatz}(\cdot)$ 總有一刻會達到 $1$。

目前已知這個敘述對於所有小於 $2.36\times 10^ {21}$ 的整數都成立。但是,這個猜想是否對所有正整數都成立,仍然是未知數。這些年來,不乏有數學家嘗試證明這個猜想,但都以失敗告終。著名的數學家 Paul Erdős 曾針對此問題給出以下評價:

"Mathematics may not be ready for such problems."

背景故事就到此為止,以下是真正的問題。

給定一個 $n$ 個正整數的陣列 $a_1,a_2,\ldots,a_n$。

接下來依序進行 $q$ 次操作,每個操作都是以下兩種類型之一。

  • $1\ l\ r$: 對於所有 $l\le i\le r$,將 $a_i$ 替換為 $\mathrm{collatz}(a_i)$。
  • $2\ l\ r$: 輸出 $\sum_{i=l}^ r a_i$。

你能在不使用 LLM 的情況下解決這個問題嗎?

Input Format

第一行輸入兩個整數 $n,q$。

第二行輸入 $n$ 個正整數 $a_1,a_2,\ldots,a_n$。

接下來輸入 $q$ 行,每一行輸入三個整數 $t,l,r$,其中第 $i$ 行代表第 $i$ 次操作。

  • $1\le n,q\le 2\times 10^ 5$
  • $1\le a_i\le 10^ 7$
  • $t\in \lbrace 1, 2\rbrace$
  • $1\le l\le r\le n$

Output Format

每個第二種操作輸出一行,這行有一個整數代表那次操作的答案。

Sample Input 1

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

Sample Output 1

29
32
19
17
39

Hints

Problem Source

YTP 2025 高中組初賽 p7

Subtasks

No. Testdata Range Constraints Score
1 0 範例測試資料 0
2 0~14 $a_i\le 26$ 6
3 0~37 無額外限制 14

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 4000 1048576 65536 1 2 3
1 4000 1048576 65536 2 3
2 4000 1048576 65536 2 3
3 4000 1048576 65536 2 3
4 4000 1048576 65536 2 3
5 4000 1048576 65536 2 3
6 4000 1048576 65536 2 3
7 4000 1048576 65536 2 3
8 4000 1048576 65536 2 3
9 4000 1048576 65536 2 3
10 4000 1048576 65536 2 3
11 4000 1048576 65536 2 3
12 4000 1048576 65536 2 3
13 4000 1048576 65536 2 3
14 4000 1048576 65536 2 3
15 4000 1048576 65536 3
16 4000 1048576 65536 3
17 4000 1048576 65536 3
18 4000 1048576 65536 3
19 4000 1048576 65536 3
20 4000 1048576 65536 3
21 4000 1048576 65536 3
22 4000 1048576 65536 3
23 4000 1048576 65536 3
24 4000 1048576 65536 3
25 4000 1048576 65536 3
26 4000 1048576 65536 3
27 4000 1048576 65536 3
28 4000 1048576 65536 3
29 4000 1048576 65536 3
30 4000 1048576 65536 3
31 4000 1048576 65536 3
32 4000 1048576 65536 3
33 4000 1048576 65536 3
34 4000 1048576 65536 3
35 4000 1048576 65536 3
36 4000 1048576 65536 3
37 4000 1048576 65536 3