結果
問題 | No.2942 Sigma Music Game Level Problem |
ユーザー | tobisatis |
提出日時 | 2024-10-18 22:17:24 |
言語 | C# (.NET 8.0.203) |
結果 |
AC
|
実行時間 | 2,210 ms / 6,000 ms |
コード長 | 4,983 bytes |
コンパイル時間 | 16,108 ms |
コンパイル使用メモリ | 168,676 KB |
実行使用メモリ | 292,636 KB |
最終ジャッジ日時 | 2024-11-15 16:13:25 |
合計ジャッジ時間 | 41,929 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
30,976 KB |
testcase_01 | AC | 65 ms
30,976 KB |
testcase_02 | AC | 71 ms
31,104 KB |
testcase_03 | AC | 65 ms
31,232 KB |
testcase_04 | AC | 65 ms
31,208 KB |
testcase_05 | AC | 66 ms
31,092 KB |
testcase_06 | AC | 66 ms
31,084 KB |
testcase_07 | AC | 66 ms
31,232 KB |
testcase_08 | AC | 67 ms
31,540 KB |
testcase_09 | AC | 69 ms
31,488 KB |
testcase_10 | AC | 68 ms
31,348 KB |
testcase_11 | AC | 736 ms
143,104 KB |
testcase_12 | AC | 1,761 ms
147,328 KB |
testcase_13 | AC | 1,920 ms
114,696 KB |
testcase_14 | AC | 831 ms
144,512 KB |
testcase_15 | AC | 432 ms
144,748 KB |
testcase_16 | AC | 1,777 ms
109,584 KB |
testcase_17 | AC | 373 ms
94,704 KB |
testcase_18 | AC | 1,303 ms
130,944 KB |
testcase_19 | AC | 2,210 ms
146,176 KB |
testcase_20 | AC | 435 ms
128,512 KB |
testcase_21 | AC | 2,045 ms
170,368 KB |
testcase_22 | AC | 2,046 ms
169,984 KB |
testcase_23 | AC | 688 ms
99,328 KB |
testcase_24 | AC | 68 ms
31,080 KB |
testcase_25 | AC | 66 ms
31,072 KB |
testcase_26 | AC | 1,465 ms
292,636 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (114 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
namespace AtCoder; #nullable enable using System.Numerics; class SegmentTree { public static SegmentTree<TMonoid, TOperator> Build<TMonoid, TOperator>(TMonoid[] initial, TOperator op) where TOperator : struct, ISegmentTreeOperator<TMonoid> => new(initial, op); } interface ISegmentTreeOperator<TMonoid> { TMonoid IdentityElement { get; } TMonoid Operation(TMonoid x, TMonoid y); } partial class SegmentTree<TMonoid, TOperator> where TOperator : struct, ISegmentTreeOperator<TMonoid> { public int BaseSize { get; init; } protected int Height { get; init; } protected TOperator Op { get; init; } protected TMonoid[] Values { get; init; } public SegmentTree(TMonoid[] initial, TOperator op = default) { Op = op; (BaseSize, Height) = (1, 0); while (BaseSize < initial.Length) (BaseSize, Height) = (BaseSize << 1, Height + 1); var size = BaseSize << 1; Values = new TMonoid[size]; var values = Values.AsSpan(); for (var i = 0; i < size; i++) values[i] = op.IdentityElement; for (var i = 0; i < initial.Length; i++) values[i + BaseSize] = initial[i]; for (var i = BaseSize - 1; i > 0; i--) Update(values, i); } public TMonoid Product(int l, int r) { (l, r) = (l + BaseSize, r + BaseSize); var (resL, resR) = (Op.IdentityElement, Op.IdentityElement); var values = Values.AsSpan(); while (l < r) { if ((l & 1) == 1) resL = Op.Operation(resL, values[l++]); if ((r & 1) == 1) resR = Op.Operation(values[--r], resR); (l, r) = (l >> 1, r >> 1); } return Op.Operation(resL, resR); } public void Set(int index, TMonoid value) { var j = index + BaseSize; var values = Values.AsSpan(); values[j] = value; for (var i = 1; i <= Height; i++) Update(values, j >> i); } protected void Update(Span<TMonoid> values, int k) { values[k] = Op.Operation(values[k << 1], values[(k << 1) + 1]); } } readonly struct SumOp<TNumber> : ISegmentTreeOperator<TNumber> where TNumber : INumber<TNumber> { public TNumber IdentityElement => TNumber.Zero; public TNumber Operation(TNumber x, TNumber y) => x + y; } static class Extensions { public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } class AtCoder { object? Solve() { var n = Int(); var q = Int(); var l = Int(); var az = n.Repeat(Int); var queries = new (int, int, int)[q]; var max = l; for (var i = 0; i < q; i++) { var k = Int(); var v1 = Int(); if (k == 2) queries[i].Item3 = Int(); if (k == 3) max = v1; queries[i].Item1 = k; queries[i].Item2 = v1; } max = Math.Max(max, az.Max()); var ans = new List<(long, long)>(); var a1 = new long[max + 1]; var a2 = new long[max + 1]; for (var i = 0; i < n; i++) { var a = az[i]; a1[a] += 1; a2[a] += a; } var op = new SumOp<long>(); var t1 = SegmentTree.Build(a1, op); var t2 = SegmentTree.Build(a2, op); foreach (var (k, x, y) in queries) { if (k == 1) { t1.Set(x, t1.Product(x, x + 1) + 1); t2.Set(x, t2.Product(x, x + 1) + x); } if (k == 2) { var v1 = t1.Product(x, y + 1); var v2 = t2.Product(x, y + 1); ans.Add((v1, v2)); } } if (ans.Count == 0) return "Not Found!"; else foreach (var (x, y) in ans) Out(new[]{ x, y }, " "); return null; } public static void Main() => new AtCoder().Run(); public void Run() { var res = Solve(); if (res != null) { if (res is bool yes) res = yes ? "Yes" : "No"; sw.WriteLine(res); } sw.Flush(); } string[] input = Array.Empty<string>(); int iter = 0; readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false }; string String() { while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Trim().Split(' '), 0); return input[iter++]; } T Input<T>() where T : IParsable<T> => T.Parse(String(), null); int Int() => Input<int>(); void Out(object? x, string? separator = null) { separator ??= Environment.NewLine; if (x is System.Collections.IEnumerable obj and not string) { var firstLine = true; foreach (var item in obj) { if (!firstLine) sw.Write(separator); firstLine = false; sw.Write(item); } } else sw.Write(x); sw.WriteLine(); } }