問題一覧 > 通常問題

No.833 Cool Train

レベル : / AI推定難易度 : 1475 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 111
作問者 : Shuz* / テスター : tatyam
お気に入りにしたユーザー ProblemId : 3022 / 自分の提出
問題文最終更新日: 2019-05-24 20:46:04
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 214 (順位表) の他の問題:

Problem Statement

Shuz*-kun has a toy train consisting of $N$ cars, numbered from $1$ to $N$.
Each car $i$ has a coolness value $A_i$.
With this toy, car $i$ and car $i + 1$ can be connected and separated.
Shuz*-kun is playing with this toy, and from time to time he wants to check the coolness of the connected cars.
Initially, all cars are separated.
Write a program that can process the following queries.
1. connect $x$
If car $x$ and car $x+1$ are not connected, connect them.
2. separate $x$
If car $x$ and car $x+1$ are connected, separate them.
3. remodel $x$
Car $x$ has been remodeled, and as a result the coolness of car $x$ increased by $1$.
4. attractiveness $x$
Output the total coolness of car $x$ and all cars connected to it.

Constraints

  • $1 \le N,\ Q$ (the number of queries) $\le 10^5$
  • $1 \le A_i \le 10^9$
  • $query$ corresponds to the numbers $1\dots 4$ described above
  • When $query_i \le 2$, $1 \le x_i < N$
  • When $query_i \ge 3$, $1 \le x_i \le N$
  • All inputs are integers
  • Input

    $N\ Q$
    $A_1\ A_2\ \dots\ A_N$
    $query_1\ x_1$
    $query_2\ x_2$
    $\vdots$
    $query_Q\ x_Q$
    

    Output

    For each attractiveness query, output the coolness on one line. Print a newline at the end.

    Sample

    Sample 1
    Input
    2 7
    1 3
    4 1
    4 2
    1 1
    4 1
    4 2
    3 1
    4 1
    
    Output
    1
    3
    4
    4
    5

    Sample 2
    Input
    10 10
    1 3 10 20 3 4 12 41 2 40
    1 2
    1 4
    1 5
    4 1
    4 4
    3 2
    1 3
    2 5
    4 2
    4 6
    Output
    1
    27
    37
    4
    

    提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。