結果

問題 No.2306 [Cherry 5th Tune C] ウソツキタマシイ
ユーザー kanenistkanenist
提出日時 2023-05-26 12:50:50
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,632 ms / 2,000 ms
コード長 664 bytes
コンパイル時間 2,330 ms
コンパイル使用メモリ 74,216 KB
実行使用メモリ 59,800 KB
最終ジャッジ日時 2024-11-27 20:21:32
合計ジャッジ時間 40,674 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	long a[] = new long[m + 1];
    	for(int i = 1; i <= m; i++)a[i] = sc.nextInt();
    	int q = sc.nextInt();
    	long sum = 0;
    	for(int h = 1; h <= m; h++){
    		sum += a[h]*a[h];
    	}
    	for(int i = 0; i < q; i++){
    		
    		int a1 = sc.nextInt();
    		int b = sc.nextInt();
    		int c = sc.nextInt();
    		sum -= a[a1]*a[a1] + a[c] * a[c];
    		a[a1] -= b;
    		a[c] += b;
    		sum += a[a1]*a[a1] + a[c] * a[c];
    		System.out.println(sum);
    	}
    }
}
0