結果
問題 | No.1332 Range Nearest Query |
ユーザー | さかぽん |
提出日時 | 2021-01-08 23:20:30 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,816 bytes |
コンパイル時間 | 4,259 ms |
コンパイル使用メモリ | 110,080 KB |
実行使用メモリ | 57,464 KB |
最終ジャッジ日時 | 2024-11-16 18:06:06 |
合計ジャッジ時間 | 21,362 ms |
ジャッジサーバーID (参考情報) |
judge4 / 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 | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; class D { static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); static (int, int) Read2() { var a = Read(); return (a[0], a[1]); } static long[] ReadL() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); static void Main() { Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var n = int.Parse(Console.ReadLine()); var a = Read(); var qc = int.Parse(Console.ReadLine()); var qs = Array.ConvertAll(new bool[qc], _ => Read()); var st = new ST1<int>(n, Math.Min, int.MinValue, a); foreach (var q in qs) { var (l, r, x) = (q[0], q[1], q[2]); Console.WriteLine(st.Aggregate(l, r + 1, int.MinValue, (p, n, v) => Math.Abs(x - v))); } Console.Out.Flush(); } } class ST1<TV> { public struct STNode { public int i; public static implicit operator STNode(int i) => new STNode { i = i }; public override string ToString() => $"{i}"; public STNode Parent => i >> 1; public STNode Child0 => i << 1; public STNode Child1 => (i << 1) + 1; public STNode LastLeft(int length) => i * length; public STNode LastRight(int length) => (i + 1) * length; } // Power of 2 public int n2 = 1; public TV[] a2; public Func<TV, TV, TV> Union; public TV v0; // 全ノードを、零元を表す値で初期化します (零元の Union もまた零元)。 public ST1(int n, Func<TV, TV, TV> union, TV _v0, TV[] a0 = null) { while (n2 < n << 1) n2 <<= 1; a2 = new TV[n2]; Union = union; v0 = _v0; if (!Equals(v0, default(TV)) || a0 != null) Init(a0); } public void Init(TV[] a0 = null) { if (a0 == null) { for (int i = 1; i < n2; ++i) a2[i] = v0; } else { Array.Copy(a0, 0, a2, n2 >> 1, a0.Length); for (int i = (n2 >> 1) + a0.Length; i < n2; ++i) a2[i] = v0; for (int i = (n2 >> 1) - 1; i > 0; --i) a2[i] = Union(a2[i << 1], a2[(i << 1) + 1]); } } public STNode Actual(int i) => (n2 >> 1) + i; public int Original(STNode n) => n.i - (n2 >> 1); public TV this[STNode n] { get { return a2[n.i]; } set { a2[n.i] = value; } } // Bottom-up public void Set(int i, TV v) { var n = Actual(i); a2[n.i] = v; while ((n = n.Parent).i > 0) a2[n.i] = Union(a2[n.Child0.i], a2[n.Child1.i]); } public TV Get(int i) => a2[(n2 >> 1) + i]; // 範囲の昇順 public TV Get(int l_in, int r_ex) => Aggregate(l_in, r_ex, v0, (p, n, l) => Union(p, a2[n.i])); // 範囲の昇順 // (previous, node, length) => result public TR Aggregate<TR>(int l_in, int r_ex, TR r0, Func<TR, STNode, int, TR> func) { int al = (n2 >> 1) + l_in, ar = (n2 >> 1) + r_ex; var rv = r0; while (al < ar) { var length = al & -al; while (al + length > ar) length >>= 1; rv = func(rv, al / length, length); al += length; } return rv; } }