結果
問題 | No.878 Range High-Element Query |
ユーザー | keymoon |
提出日時 | 2019-09-06 22:49:32 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 662 ms / 2,000 ms |
コード長 | 2,805 bytes |
コンパイル時間 | 1,401 ms |
コンパイル使用メモリ | 117,092 KB |
実行使用メモリ | 38,656 KB |
最終ジャッジ日時 | 2024-06-24 20:20:24 |
合計ジャッジ時間 | 7,145 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
19,712 KB |
testcase_01 | AC | 47 ms
20,480 KB |
testcase_02 | AC | 48 ms
20,480 KB |
testcase_03 | AC | 46 ms
19,968 KB |
testcase_04 | AC | 47 ms
20,224 KB |
testcase_05 | AC | 48 ms
20,864 KB |
testcase_06 | AC | 46 ms
20,224 KB |
testcase_07 | AC | 47 ms
20,096 KB |
testcase_08 | AC | 50 ms
20,736 KB |
testcase_09 | AC | 48 ms
20,608 KB |
testcase_10 | AC | 36 ms
19,968 KB |
testcase_11 | AC | 523 ms
36,992 KB |
testcase_12 | AC | 487 ms
33,920 KB |
testcase_13 | AC | 400 ms
34,048 KB |
testcase_14 | AC | 292 ms
31,360 KB |
testcase_15 | AC | 451 ms
34,432 KB |
testcase_16 | AC | 618 ms
38,016 KB |
testcase_17 | AC | 662 ms
38,656 KB |
testcase_18 | AC | 656 ms
38,400 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 n = nq[0]; var q = nq[1]; var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); //Mo #if DEBUG var shiftRange = 1; #else var shiftRange = 8; #endif var chunkSize = 1 << shiftRange; var res = new int[q]; var queries = Enumerable.Range(0, q).Select(Index => new { Index, Elem = Query.Parse(Console.ReadLine()) }).ToArray(); foreach (var query in queries.Where(x => chunkSize >= x.Elem.Length)) { int count = 0; int curMax = 0; for (int i = query.Elem.L; i <= query.Elem.R; i++) { if (curMax < a[i]) { curMax = a[i]; count++; } } res[query.Index] = count; } foreach (var chunk in queries.Where(x => chunkSize < x.Elem.Length).GroupBy(x => x.Elem.L >> shiftRange)) { List<int> highCand = new List<int>(); var chunkEnd = Min(n - 1, (chunk.Key + 1) << shiftRange); highCand.Add(-1); var curInd = chunkEnd; foreach (var query in chunk.OrderBy(x => x.Elem.R)) { while (curInd <= query.Elem.R) { if (highCand.Last() < a[curInd]) highCand.Add(a[curInd]); curInd++; } int count = 0; int curMax = 0; for (int i = query.Elem.L; i < chunkEnd; i++) { if (curMax < a[i]) { curMax = a[i]; count++; } } res[query.Index] = count + highCand.Count - (~highCand.BinarySearch(curMax)); } } Console.WriteLine(string.Join("\n", res)); } } struct Query { public int L; public int R; public int Length => R - L + 1; public static Query Parse(string s) { var qlr = s.Split().Select(int.Parse).ToArray(); return new Query() { L = qlr[1] - 1, R = qlr[2] - 1, }; } }