結果

問題 No.878 Range High-Element Query
ユーザー keymoonkeymoon
提出日時 2019-09-06 22:33:41
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,268 bytes
コンパイル時間 3,763 ms
コンパイル使用メモリ 107,240 KB
実行使用メモリ 43,072 KB
最終ジャッジ日時 2023-09-07 01:21:06
合計ジャッジ時間 10,621 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
24,052 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 719 ms
43,072 KB
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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
        //伸ばしていく時に高くなりうる要素を集めて、
        var chunkSize = 256;
        var res = new int[q];
        foreach (var chunk in 
            Enumerable.Range(0, q)
            .Select(Index => new { Index, Elem = Query.Parse(Console.ReadLine()) })
            .GroupBy(x => x.Elem.L >> 8))
        {
            List<int> highCand = new List<int>();
            var chunkEnd = Min(q, (chunk.Key + 1) << 8);
            highCand.Add(-1);
            var curInd = chunkEnd;
            foreach (var item in chunk.OrderBy(x => x.Elem.R))
            {
                while (curInd < item.Elem.R)
                {
                    if (highCand.Last() < a[curInd])
                        highCand.Add(a[curInd]);
                    curInd++;
                }
                int count = 0;
                int curMax = 0;
                for (int i = item.Elem.L; i < chunkEnd; i++)
                {
                    if (curMax < a[i])
                    {
                        curMax = a[i];
                        count++;
                    }
                }
                res[item.Index] = count + highCand.Count - (~highCand.BinarySearch(curMax));
            }
        }
        Console.WriteLine(string.Join("\n", res));
    }
}

struct Query
{
    public int L;
    public int R;
    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,
        };
    }
}
0