結果

問題 No.1558 Derby Live
ユーザー 👑 kakel-sankakel-san
提出日時 2023-12-29 00:48:30
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 385 ms / 2,000 ms
コード長 4,884 bytes
コンパイル時間 10,515 ms
コンパイル使用メモリ 158,972 KB
実行使用メモリ 180,484 KB
最終ジャッジ日時 2023-12-29 00:48:56
合計ジャッジ時間 23,674 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 333 ms
70,760 KB
testcase_01 AC 373 ms
71,992 KB
testcase_02 AC 83 ms
32,804 KB
testcase_03 AC 268 ms
64,804 KB
testcase_04 AC 190 ms
60,532 KB
testcase_05 AC 181 ms
60,520 KB
testcase_06 AC 260 ms
65,172 KB
testcase_07 AC 91 ms
35,364 KB
testcase_08 AC 258 ms
65,964 KB
testcase_09 AC 275 ms
70,472 KB
testcase_10 AC 269 ms
70,468 KB
testcase_11 AC 282 ms
70,796 KB
testcase_12 AC 298 ms
70,768 KB
testcase_13 AC 321 ms
66,584 KB
testcase_14 AC 313 ms
66,204 KB
testcase_15 AC 312 ms
66,316 KB
testcase_16 AC 333 ms
66,188 KB
testcase_17 AC 349 ms
70,408 KB
testcase_18 AC 352 ms
70,432 KB
testcase_19 AC 366 ms
70,468 KB
testcase_20 AC 361 ms
70,476 KB
testcase_21 AC 347 ms
70,444 KB
testcase_22 AC 372 ms
70,460 KB
testcase_23 AC 361 ms
70,476 KB
testcase_24 AC 350 ms
70,452 KB
testcase_25 AC 372 ms
70,464 KB
testcase_26 AC 368 ms
70,476 KB
testcase_27 AC 346 ms
70,444 KB
testcase_28 AC 382 ms
70,584 KB
testcase_29 AC 362 ms
70,488 KB
testcase_30 AC 346 ms
70,432 KB
testcase_31 AC 385 ms
70,592 KB
testcase_32 AC 365 ms
70,488 KB
testcase_33 AC 89 ms
32,932 KB
testcase_34 AC 86 ms
180,484 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (106 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m, q) = (c[0], c[1], c[2]);
        var query = NArr(q);
        var seg = new SegmentTree<int[]>(m, new SegOp(n));
        var ans = new List<string>();
        foreach (var que in query)
        {
            if (que[0] == 1)
            {
                seg[que[1] - 1] = que[2..].Select(qi => qi - 1).ToArray();
            }
            else if (que[0] == 2)
            {
                var order = seg.Prod(0, que[1]);
                var nq = new int[n];
                for (var i = 0; i < n; ++i) nq[order[i]] = i + 1;
                ans.Add(string.Join(" ", nq));
            }
            else
            {
                var order = seg.Prod(que[1] - 1, que[2]);
                var pt = 0;
                for (var i = 0; i < n; ++i) pt += Math.Abs(i - order[i]);
                ans.Add(pt.ToString());
            }
        }
        WriteLine(string.Join("\n", ans));
    }
    struct SegOp : ISegmentTreeOperator<int[]>
    {
        public int n;
        public int[] Identity
        {
            get
            {
                var id = new int[n];
                for (var i = 0; i < n; ++i) id[i] = i;
                return id;
            }
        }
        public int[] Operate(int[] x, int[] y)
        {
            var arr = new int[n];
            for (var i = 0; i < n; ++i) arr[i] = y[x[i]];
            return arr;
        }
        public SegOp(int n)
        {
            this.n = n;
        }
    }
    interface ISegmentTreeOperator<T>
    {
        T Identity { get; }
        T Operate(T x, T y);
    }
    class SegmentTree<T>
    {
        int size;
        int log;
        T[] d;
        ISegmentTreeOperator<T> op;
        void Update(int k)
        {
            d[k] = op.Operate(d[2 * k], d[2 * k + 1]);
        }
        public SegmentTree(int n, ISegmentTreeOperator<T> op)
        {
            this.op = op;
            size = 1;
            while (size < n) size <<= 1;
            log = CountRZero(size);
            d = new T[2 * size];
            for (var i = 0; i < d.Length; ++i) d[i] = op.Identity;
        }
        public SegmentTree(T[] v, ISegmentTreeOperator<T> op)
        {
            this.op = op;
            size = 1;
            while (size < v.Length) size <<= 1;
            log = CountRZero(size);
            d = new T[2 * size];
            for (var i = 0; i < size; ++i) d[i] = op.Identity;
            for (var i = 0; i < v.Length; ++i) d[size + i] = v[i];
            for (var i = size - 1; i >= 1; --i) Update(i);
        }
        int CountRZero(int n)
        {
            var ans = 0;
            while (n % 2 == 0)
            {
                ++ans;
                n >>= 1;
            }
            return ans;
        }
        public T this[int p]
        {
            get { return d[p + size]; }
            set
            {
                p += size;
                d[p] = value;
                for (var i = 1; i <= log; ++i) Update(p >> i);
            }
        }
        public T Prod(int l, int r)
        {
            var sml = op.Identity;
            var smr = op.Identity;
            l += size;
            r += size;
            while (l < r)
            {
                if ((l & 1) != 0) sml = op.Operate(sml, d[l++]);
                if ((r & 1) != 0) smr = op.Operate(d[--r], smr);
                l >>= 1;
                r >>= 1;
            }
            return op.Operate(sml, smr);
        }
        T AllProd() => d[1];
        int MinLeft(int r, Predicate<T> f)
        {
            if (r == 0) return 0;
            r += size;
            T sm = op.Identity;
            do
            {
                r--;
                while (r > 1 && (r % 2) != 0) r >>= 1;
                if (!f(op.Operate(d[r], sm)))
                {
                    while (r < size)
                    {
                        r = 2 * r + 1;
                        if (f(op.Operate(d[r], sm)))
                        {
                            sm = op.Operate(d[r], sm);
                            r--;
                        }
                    }
                    return r + 1 - size;
                }
                sm = op.Operate(d[r], sm);
            }
            while ((r & -r) != r);
            return 0;
        }
    }
}
0