結果
問題 | No.875 Range Mindex Query |
ユーザー | keymoon |
提出日時 | 2019-11-20 17:35:02 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 699 ms / 2,000 ms |
コード長 | 2,655 bytes |
コンパイル時間 | 2,467 ms |
コンパイル使用メモリ | 116,548 KB |
実行使用メモリ | 38,656 KB |
最終ジャッジ日時 | 2024-10-06 23:07:43 |
合計ジャッジ時間 | 7,963 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
18,944 KB |
testcase_01 | AC | 36 ms
19,712 KB |
testcase_02 | AC | 38 ms
20,224 KB |
testcase_03 | AC | 29 ms
19,072 KB |
testcase_04 | AC | 34 ms
19,968 KB |
testcase_05 | AC | 34 ms
19,840 KB |
testcase_06 | AC | 35 ms
19,584 KB |
testcase_07 | AC | 36 ms
20,224 KB |
testcase_08 | AC | 34 ms
20,096 KB |
testcase_09 | AC | 34 ms
19,712 KB |
testcase_10 | AC | 38 ms
19,840 KB |
testcase_11 | AC | 490 ms
37,376 KB |
testcase_12 | AC | 416 ms
32,896 KB |
testcase_13 | AC | 337 ms
37,760 KB |
testcase_14 | AC | 333 ms
37,376 KB |
testcase_15 | AC | 479 ms
38,656 KB |
testcase_16 | AC | 649 ms
36,608 KB |
testcase_17 | AC | 699 ms
37,120 KB |
testcase_18 | AC | 657 ms
37,376 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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); } }