結果

問題 No.2306 [Cherry 5th Tune C] ウソツキタマシイ
ユーザー simansiman
提出日時 2023-05-19 23:04:22
言語 Ruby
(3.3.0)
結果
AC  
実行時間 428 ms / 2,000 ms
コード長 395 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 11,396 KB
実行使用メモリ 25,048 KB
最終ジャッジ日時 2023-08-23 01:03:43
合計ジャッジ時間 12,367 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,144 KB
testcase_01 AC 79 ms
15,304 KB
testcase_02 AC 82 ms
15,140 KB
testcase_03 AC 81 ms
15,140 KB
testcase_04 AC 80 ms
15,164 KB
testcase_05 AC 81 ms
15,028 KB
testcase_06 AC 82 ms
15,060 KB
testcase_07 AC 303 ms
21,072 KB
testcase_08 AC 129 ms
19,680 KB
testcase_09 AC 216 ms
21,156 KB
testcase_10 AC 205 ms
15,412 KB
testcase_11 AC 228 ms
20,316 KB
testcase_12 AC 290 ms
24,896 KB
testcase_13 AC 220 ms
21,440 KB
testcase_14 AC 193 ms
20,656 KB
testcase_15 AC 355 ms
20,308 KB
testcase_16 AC 360 ms
17,752 KB
testcase_17 AC 422 ms
24,940 KB
testcase_18 AC 425 ms
24,968 KB
testcase_19 AC 428 ms
25,048 KB
testcase_20 AC 424 ms
24,908 KB
testcase_21 AC 420 ms
25,024 KB
testcase_22 AC 424 ms
24,904 KB
testcase_23 AC 424 ms
25,004 KB
testcase_24 AC 426 ms
24,852 KB
testcase_25 AC 418 ms
25,008 KB
testcase_26 AC 421 ms
24,832 KB
testcase_27 AC 388 ms
24,252 KB
testcase_28 AC 420 ms
24,048 KB
testcase_29 AC 366 ms
15,188 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
Q = gets.to_i
ans = A.map { |a| a ** 2 }.sum

Q.times do
  c, k, d = gets.split.map(&:to_i)

  before_c = A[c - 1]
  before_d = A[d - 1]

  after_c = before_c - k
  after_d = before_d + k

  ans -= before_c ** 2
  ans -= before_d ** 2
  ans += after_c ** 2
  ans += after_d ** 2

  A[c - 1] = after_c
  A[d - 1] = after_d

  puts ans
end
0