結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー tobisatistobisatis
提出日時 2024-10-18 22:17:24
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 2,000 ms / 6,000 ms
コード長 4,983 bytes
コンパイル時間 23,968 ms
コンパイル使用メモリ 169,240 KB
実行使用メモリ 295,188 KB
最終ジャッジ日時 2024-10-18 22:49:55
合計ジャッジ時間 31,167 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
30,968 KB
testcase_01 AC 59 ms
30,932 KB
testcase_02 AC 63 ms
31,104 KB
testcase_03 AC 60 ms
30,976 KB
testcase_04 AC 62 ms
31,104 KB
testcase_05 AC 63 ms
31,360 KB
testcase_06 AC 64 ms
31,104 KB
testcase_07 AC 63 ms
31,232 KB
testcase_08 AC 65 ms
31,352 KB
testcase_09 AC 65 ms
31,224 KB
testcase_10 AC 66 ms
31,360 KB
testcase_11 AC 717 ms
145,744 KB
testcase_12 AC 1,525 ms
160,072 KB
testcase_13 AC 1,711 ms
117,468 KB
testcase_14 AC 732 ms
147,844 KB
testcase_15 AC 366 ms
145,596 KB
testcase_16 AC 1,581 ms
109,784 KB
testcase_17 AC 343 ms
95,308 KB
testcase_18 AC 1,127 ms
132,668 KB
testcase_19 AC 2,000 ms
148,116 KB
testcase_20 AC 389 ms
131,652 KB
testcase_21 AC 1,725 ms
173,752 KB
testcase_22 AC 1,724 ms
171,976 KB
testcase_23 AC 643 ms
100,920 KB
testcase_24 AC 61 ms
31,104 KB
testcase_25 AC 60 ms
31,060 KB
testcase_26 AC 1,404 ms
295,188 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (97 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/

ソースコード

diff #

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();
    }
}
0