結果
問題 | No.877 Range ReLU Query |
ユーザー | keymoon |
提出日時 | 2019-09-06 22:08:26 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,560 bytes |
コンパイル時間 | 2,187 ms |
コンパイル使用メモリ | 118,152 KB |
実行使用メモリ | 54,276 KB |
最終ジャッジ日時 | 2024-06-24 18:02:53 |
合計ジャッジ時間 | 8,385 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
19,840 KB |
testcase_01 | AC | 46 ms
20,608 KB |
testcase_02 | AC | 47 ms
20,736 KB |
testcase_03 | AC | 50 ms
20,480 KB |
testcase_04 | AC | 47 ms
20,096 KB |
testcase_05 | AC | 42 ms
20,224 KB |
testcase_06 | AC | 47 ms
20,480 KB |
testcase_07 | AC | 45 ms
20,096 KB |
testcase_08 | AC | 48 ms
20,608 KB |
testcase_09 | AC | 45 ms
20,352 KB |
testcase_10 | AC | 46 ms
20,736 KB |
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 | - |
コンパイルメッセージ
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<int> rsq = new SegmentTree<int>(nq[0], 0, (x, y) => x + y); SegmentTree<int> rcq = new SegmentTree<int>(nq[0], 0, (x, y) => x + y); Stack<int> stack = new Stack<int>(a.Select((Elem, Index) => new { Elem, Index }).OrderBy(x => x.Elem).Select(x => x.Index)); int[] res = new int[nq[1]]; //大きいクエリから降ってくるので、できるところから追加 foreach (var item in Enumerable.Range(0, nq[1]).Select(Index => new { Index, Elem = Console.ReadLine().Split().Select(int.Parse).ToArray() }).OrderByDescending(x => x.Elem[3])) { var l = item.Elem[1] - 1; var r = item.Elem[2] - 1; var x = item.Elem[3]; while (stack.Count != 0 && x <= a[stack.Peek()]) { var ind = stack.Pop(); rsq[ind] = a[ind]; rcq[ind] = 1; } res[item.Index] = rsq.Query(l, r) - rcq.Query(l, r) * x; } Console.WriteLine(string.Join("\n", res)); } } 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 = 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); } }