結果
| 問題 | No.1000 Point Add and Array Add |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-04 22:54:41 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 358 ms / 2,000 ms |
| コード長 | 2,856 bytes |
| 記録 | |
| コンパイル時間 | 8,811 ms |
| コンパイル使用メモリ | 169,192 KB |
| 実行使用メモリ | 264,356 KB |
| 最終ジャッジ日時 | 2025-12-04 22:54:57 |
| 合計ジャッジ時間 | 15,219 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (121 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics.X86;
using System.Runtime.Intrinsics.Arm;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var c = NList;
var (n, q) = (c[0], c[1]);
var a = NList;
var query = SList(q);
var ft = new FenwickTree(n + 1);
var b = new long[n];
foreach (var que in query)
{
var s = que.Split();
var x = int.Parse(s[1]);
var y = int.Parse(s[2]);
if (que[0] == 'A')
{
--x;
var px = ft.Sum(x);
b[x] += px * a[x];
a[x] += y;
ft.Add(x, -px);
ft.Add(x + 1, px);
}
else
{
ft.Add(x - 1, 1);
ft.Add(y, -1);
}
}
for (var i = 0; i < n; ++i) b[i] += a[i] * ft.Sum(i);
WriteLine(string.Join(" ", b));
}
class FenwickTree
{
int size;
long[] tree;
public FenwickTree(int size)
{
this.size = size;
tree = new long[size + 2];
}
public void Add(int index, long value)
{
++index;
for (var x = index; x <= size; x += (x & -x)) tree[x] += value;
}
/// <summary>先頭からindexまでの和(include index)</summary>
public long Sum(int index)
{
if (index < 0) return 0;
++index;
var sum = 0L;
for (var x = index; x > 0; x -= (x & -x)) sum += tree[x];
return sum;
}
public long Get(int index)
{
if (index == 0) return Sum(0);
return Sum(index) - Sum(index - 1);
}
/// <summary>Sum(x) >= value となる最小のxを求める</summary>
// 各要素は非負であること
public int LowerBound(long value)
{
if (value < 0) return -1;
var x = 0;
var b = 1;
while (b * 2 <= size) b <<= 1;
for (var k = b; k > 0; k >>= 1)
{
if (x + k <= size && tree[x + k] < value)
{
value -= tree[x + k];
x += k;
}
}
return x;
}
}
}