0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

この記事は 共通テスト手順記述標準言語 (DNCL) Advent Calendar 2025 の21日目の記事です。

DNCLで累積和を書いていきます。

累積和とは

累積和とは、配列の各要素の先頭からの合計を順に計算した配列のことです。累積和を使うと好きな区間の合計を高速に求めることができます。

0 1 2 3 4
配列s - 3 1 4 1 5
累積和a 0 3 4 8 9 14

上のように累積和ss[i] = s[0] + s[1] + s[2] + ・・・ + s[i]となります。
配列aのA番目からB番目の和はs[B] - s[A - 1]で求めることができます。

累積和を書く

配列hairetsuの累積和を配列ruisekiに入れていきます。配列の添え字は0から始まります。
配列hairetsul番目からr番目の和を表示します。

hairetsu ← {42, 87, 15, 63, 29, 54, 71, 38, 96, 12, 48, 75, 61, 33, 80}
kosu ← 15
ruiseki ← {0}
i を1から kosu まで1ずつ増やしながら
|  ruiseki[i] ← ruiseki[i - 1] + hairetsu[i-1]
を繰り返す。

l ← 7
r ← 12
(ruiseki[r] - ruiseki[l-1]) を表示する
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?