結果

問題 No.1618 Convolution?
ユーザー さかぽん
提出日時 2021-07-22 22:53:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 322 ms / 2,000 ms
コード長 1,201 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 113,472 KB
実行使用メモリ 68,008 KB
最終ジャッジ日時 2024-07-17 19:21:00
合計ジャッジ時間 8,112 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class C
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
	static long[] ReadL() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	static void Main() => Console.WriteLine(Solve());
	static object Solve()
	{
		var n = int.Parse(Console.ReadLine());
		var a = ReadL();
		var b = ReadL();

		var ab = a.Zip(b, (x, y) => x + y).ToArray();
		var rsq = new StaticRSQ1(ab);

		var c = new long[2 * n];
		var t = 0L;

		for (int i = 1; i <= n; i++)
		{
			t += rsq.GetSum(0, i);
			c[i] = t;
		}

		for (int i = 1; i < n; i++)
		{
			t -= n * ab[i - 1];
			t += rsq.GetSum(i, n);
			c[n + i] = t;
		}

		return string.Join(" ", c);
	}
}

public class StaticRSQ1
{
	int n;
	long[] s;
	public long[] Raw => s;
	public StaticRSQ1(long[] a)
	{
		n = a.Length;
		s = new long[n + 1];
		for (int i = 0; i < n; ++i) s[i + 1] = s[i] + a[i];
	}

	// [l, r)
	// 範囲外のインデックスも可。
	public long GetSum(int l, int r)
	{
		if (r < 0 || n < l) return 0;
		if (l < 0) l = 0;
		if (n < r) r = n;
		return s[r] - s[l];
	}
}
0