結果

問題 No.2306 [Cherry 5th Tune C] ウソツキタマシイ
ユーザー anonymously
提出日時 2023-05-19 21:49:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 248 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 1,804 ms
コンパイル使用メモリ 168,464 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-18 02:32:53
合計ジャッジ時間 8,391 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
	//最初, i=1,2,…,M それぞれに対して, 色 i の魂が N 個中 Ai個ある.
	unsigned long n;
	size_t m;
	cin>>n>>m;
	vector<long> a(m);
	long soulPower=0;
	for(size_t i=0;i<m;i++){
		cin>>a.at(i);
		soulPower+=(a.at(i)*a.at(i));
	}
	size_t q;
	cin>>q;
	while(q--){
		//色Cである魂のうち, K個は本当は色Dである.
		size_t c,d;
		long k;
		cin>>c>>k>>d;
		//ソウルパワー変化
		//a[c-1]⇒a[c-1]-k
		long b=a.at(c-1)-k;
		soulPower+=(b*b-a.at(c-1)*a.at(c-1));
		a.at(c-1)=b;
		//a[d-1]⇒a[d-1]+k
		b=a.at(d-1)+k;
		soulPower+=(b*b-a.at(d-1)*a.at(d-1));
		a.at(d-1)=b;
		cout<<soulPower<<endl;
	}
	return EXIT_SUCCESS;	
}
0