結果

問題 No.875 Range Mindex Query
ユーザー bluemeganebluemegane
提出日時 2021-04-30 07:04:57
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 638 ms / 2,000 ms
コード長 2,208 bytes
コンパイル時間 1,052 ms
コンパイル使用メモリ 70,036 KB
実行使用メモリ 36,576 KB
最終ジャッジ日時 2023-09-25 07:41:11
合計ジャッジ時間 7,274 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,600 KB
testcase_01 AC 70 ms
19,572 KB
testcase_02 AC 71 ms
21,680 KB
testcase_03 AC 62 ms
21,624 KB
testcase_04 AC 70 ms
21,784 KB
testcase_05 AC 70 ms
21,796 KB
testcase_06 AC 69 ms
21,716 KB
testcase_07 AC 70 ms
23,776 KB
testcase_08 AC 68 ms
21,880 KB
testcase_09 AC 69 ms
21,804 KB
testcase_10 AC 70 ms
23,856 KB
testcase_11 AC 430 ms
32,884 KB
testcase_12 AC 368 ms
30,472 KB
testcase_13 AC 312 ms
34,048 KB
testcase_14 AC 317 ms
35,672 KB
testcase_15 AC 407 ms
36,200 KB
testcase_16 AC 607 ms
34,244 KB
testcase_17 AC 638 ms
36,576 KB
testcase_18 AC 626 ms
36,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Linq;
using static System.Math;
using System;

public class rmq
{
    private readonly int INTMAX = int.MaxValue;
    private int[] dat;
    private static int size;

    public rmq(int n)
    {
        size = 1;
        while (size < n) size *= 2;
        dat = Enumerable.Repeat(INTMAX, 2 * size - 1).ToArray();
    }

    public void update(int i, int a)
    {
        i += size - 1;
        dat[i] = a;
        while (i > 0)
        {
            i = (i - 1) / 2;
            dat[i] = Min(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }

    private int query(int a, int b, int k, int L, int r)
    {
        if (r <= a || b <= L) return INTMAX;
        if (a <= L && r <= b) return dat[k];
        else
        {
            int vL = query(a, b, k * 2 + 1, L, (L + r) / 2);
            int vr = query(a, b, k * 2 + 2, (L + r) / 2, r);
            return Min(vL, vr);
        }
    }
    public int query(int a, int b) => query(a, b, 0, 0, size);
}

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var q = int.Parse(line[1]);
        getAns(n, q);
    }
    static void getAns(int n, int q)
    {
        var rmq = new rmq(n + 10);
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var reva = new int[n + 1];
        for (int i = 0; i < n; i++)
        {
            rmq.update(i, a[i]);
            reva[a[i]] = i;
        }
        for (int i = 0; i < q; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var L = int.Parse(line[1]) - 1;
            var r = int.Parse(line[2]) - 1;
            if (line[0] == "1")
            {
                rmq.update(L, a[r]);
                rmq.update(r, a[L]);
                var temp= a[L];
                a[L] = a[r];
                a[r] = temp;
                 temp = reva[a[L]];
                reva[a[L]] = reva[a[r]];
                reva[a[r]] = temp;
            }
            else
            {
                var w2 = rmq.query(L, r + 1);
                Console.WriteLine(reva[w2] + 1);
            }
        }
    }
}
0