結果

問題 No.2710 How many more?
ユーザー 👑 kakel-sankakel-san
提出日時 2024-04-09 23:47:00
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,370 bytes
コンパイル時間 10,404 ms
コンパイル使用メモリ 169,612 KB
実行使用メモリ 186,860 KB
最終ジャッジ日時 2024-04-09 23:47:16
合計ジャッジ時間 14,017 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
31,232 KB
testcase_01 AC 60 ms
30,976 KB
testcase_02 AC 230 ms
66,968 KB
testcase_03 AC 149 ms
52,608 KB
testcase_04 AC 132 ms
49,920 KB
testcase_05 AC 115 ms
44,256 KB
testcase_06 AC 122 ms
47,616 KB
testcase_07 AC 120 ms
44,544 KB
testcase_08 AC 110 ms
41,984 KB
testcase_09 AC 174 ms
59,776 KB
testcase_10 AC 134 ms
47,872 KB
testcase_11 AC 172 ms
56,064 KB
testcase_12 AC 244 ms
68,872 KB
testcase_13 AC 250 ms
69,624 KB
testcase_14 AC 245 ms
69,496 KB
testcase_15 AC 255 ms
69,492 KB
testcase_16 AC 254 ms
69,752 KB
testcase_17 AC 247 ms
69,616 KB
testcase_18 AC 57 ms
186,860 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (99 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, q) = (c[0], c[1]);
        var a = NList;
        var query = NMap(q);
        var list = a.ToList();
        list.Sort();
        var ans = new int[q];
        for (var i = 0; i < q; ++i)
        {
            var pos1 = LowerBound(0, a[query[i][0]], list) - 1;
            var pos2 = LowerBound(0, a[query[i][1]] + 1, list) - 1;
            ans[i] = Math.Max(0, pos1 - pos2);
        }
        WriteLine(string.Join("\n", ans));
    }
    static int LowerBound(int left, int min, IList<int> list)
    {
        if (list[left] >= min) return left;
        var ng = left;
        var ok = list.Count;
        while (ok - ng > 1)
        {
            var center = (ng + ok) / 2;
            if (list[center] < min) ng = center;
            else ok = center;
        }
        return ok;
    }
}
0