結果

問題 No.875 Range Mindex Query
ユーザー keymoonkeymoon
提出日時 2019-11-20 17:35:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 751 ms / 2,000 ms
コード長 2,655 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 115,256 KB
実行使用メモリ 44,792 KB
最終ジャッジ日時 2024-04-16 08:06:58
合計ジャッジ時間 7,439 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
27,128 KB
testcase_01 AC 41 ms
25,568 KB
testcase_02 AC 43 ms
25,880 KB
testcase_03 AC 35 ms
25,104 KB
testcase_04 AC 40 ms
25,652 KB
testcase_05 AC 40 ms
27,756 KB
testcase_06 AC 41 ms
25,704 KB
testcase_07 AC 41 ms
27,716 KB
testcase_08 AC 41 ms
27,764 KB
testcase_09 AC 41 ms
27,740 KB
testcase_10 AC 42 ms
27,620 KB
testcase_11 AC 546 ms
43,220 KB
testcase_12 AC 453 ms
38,688 KB
testcase_13 AC 378 ms
43,984 KB
testcase_14 AC 382 ms
43,412 KB
testcase_15 AC 525 ms
44,792 KB
testcase_16 AC 670 ms
42,680 KB
testcase_17 AC 751 ms
43,380 KB
testcase_18 AC 730 ms
43,412 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        var nq = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        SegTree<Tuple<int, int>> rmq = new SegTree<Tuple<int, int>>(a.Select((x, y) => new Tuple<int, int>(x, y + 1)).ToArray(), new Tuple<int, int>(int.MaxValue, -1), (x, y) => x.Item1 < y.Item1 ? x : y);
        for (int i = 0; i < nq[1]; i++)
        {
            var query = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (query[0] == 1)
            {
                var tmp = rmq[query[1] - 1].Item1;
                rmq[query[1] - 1] = new Tuple<int, int>(rmq[query[2] - 1].Item1, query[1]);
                rmq[query[2] - 1] = new Tuple<int, int>(tmp, query[2]);
            }
            else
            {
                Console.WriteLine(rmq.Query(query[1] - 1, query[2] - 1).Item2);
            }
        }
    }
}

class SegTree<T>
{
    int LeafCount;
    T[] Data;
    T Identity;
    Func<T, T, T> Merge;
    public SegTree(T[] arr, T identity, Func<T, T, T> merge)
    {
        Identity = identity;
        Merge = merge;
        LeafCount = 1;
        while (LeafCount < arr.Length) LeafCount *= 2;
        Data = new T[LeafCount * 2];
        for (int i = 0; i < Data.Length; i++) Data[i] = identity;
        arr.CopyTo(Data, LeafCount);
        for (int i = LeafCount - 1; i >= 0; i--) Data[i] = Merge(Data[i << 1], Data[i << 1 | 1]);
    }
    public T this[int index]
    {
        get { return Data[index + LeafCount]; }
        set 
        {
            Data[index += LeafCount] = value;
            while (1 < index)
            {
                index >>= 1;
                Data[index] = Merge(Data[index << 1], Data[index << 1 | 1]);
            }
        }
    }
    public T Query(int l, int r)
    {
        l += LeafCount;
        r += LeafCount;
        T lRes = Identity;
        T rRes = Identity;
        for (; l <= r;)
        {
            if (l % 2 == 1) lRes = Merge(lRes, Data[l]);
            if (r % 2 == 0) rRes = Merge(Data[r], rRes);
            l++; r--; l >>= 1; r >>= 1;
        }
        return Merge(lRes, rRes);
    }
}
0