結果
問題 | No.875 Range Mindex Query |
ユーザー | keymoon |
提出日時 | 2019-09-06 21:30:15 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 701 ms / 2,000 ms |
コード長 | 3,321 bytes |
コンパイル時間 | 2,823 ms |
コンパイル使用メモリ | 114,936 KB |
実行使用メモリ | 38,912 KB |
最終ジャッジ日時 | 2024-06-24 16:49:55 |
合計ジャッジ時間 | 6,843 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
19,328 KB |
testcase_01 | AC | 39 ms
20,224 KB |
testcase_02 | AC | 40 ms
19,840 KB |
testcase_03 | AC | 34 ms
19,456 KB |
testcase_04 | AC | 38 ms
19,712 KB |
testcase_05 | AC | 37 ms
19,712 KB |
testcase_06 | AC | 40 ms
20,224 KB |
testcase_07 | AC | 40 ms
19,712 KB |
testcase_08 | AC | 39 ms
19,840 KB |
testcase_09 | AC | 38 ms
19,712 KB |
testcase_10 | AC | 41 ms
20,224 KB |
testcase_11 | AC | 528 ms
37,376 KB |
testcase_12 | AC | 434 ms
33,152 KB |
testcase_13 | AC | 369 ms
38,144 KB |
testcase_14 | AC | 373 ms
37,504 KB |
testcase_15 | AC | 493 ms
38,912 KB |
testcase_16 | AC | 646 ms
36,992 KB |
testcase_17 | AC | 701 ms
37,248 KB |
testcase_18 | AC | 680 ms
37,632 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(); SegmentTree<Tuple<int, int>> rmq = new SegmentTree<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 SegmentTree<T> { public int Size { get; private set; } T IdentityElement; T[] Data; Func<T, T, T> Merge; int LeafCount; public SegmentTree(int size, T identityElement, Func<T, T, T> merge) : this(Enumerable.Repeat(identityElement, size).ToArray(), identityElement, merge) { } public SegmentTree(T[] elems, T identityElement, Func<T, T, T> merge) { Size = elems.Length; Merge = merge; IdentityElement = identityElement; LeafCount = 1; while (LeafCount < elems.Length) LeafCount <<= 1; Data = new T[LeafCount << 1]; elems.CopyTo(Data, LeafCount); for (int i = elems.Length + LeafCount; i < Data.Length; i++) Data[i] = IdentityElement; for (int i = LeafCount - 1; i >= 1; i--) Data[i] = Merge(Data[i << 1], Data[(i << 1) + 1]); } public T this[int index] { get { return Data[LeafCount + index]; } set { Update(index, value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int i, T x) { i += LeafCount; Data[i] = x; while (0 < (i >>= 1)) Data[i] = Merge(Data[i << 1], Data[(i << 1) + 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Operate(int i, T x) { i += LeafCount; Data[i] = Merge(Data[i], x); while (0 < (i >>= 1)) Data[i] = Merge(Data[i << 1], Data[(i << 1) + 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int l, int r) { l += LeafCount; r += LeafCount; T lRes = IdentityElement, rRes = IdentityElement; while (l <= r) { if ((l & 1) == 1) lRes = Merge(lRes, Data[l]); if ((r & 1) == 0) rRes = Merge(Data[r], rRes); l = (l + 1) >> 1; r = (r - 1) >> 1; } return Merge(lRes, rRes); } }