結果
問題 | No.875 Range Mindex Query |
ユーザー | keymoon |
提出日時 | 2019-11-20 17:30:50 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,580 bytes |
コンパイル時間 | 2,546 ms |
コンパイル使用メモリ | 115,672 KB |
実行使用メモリ | 49,000 KB |
最終ジャッジ日時 | 2024-10-06 22:58:06 |
合計ジャッジ時間 | 7,563 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
コンパイルメッセージ
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; 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); } 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); } }