結果

問題 No.2758 RDQ
ユーザー 👑 kakel-sankakel-san
提出日時 2024-05-17 21:40:20
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 1,763 bytes
コンパイル時間 11,117 ms
コンパイル使用メモリ 166,752 KB
実行使用メモリ 191,888 KB
最終ジャッジ日時 2024-05-17 23:44:28
合計ジャッジ時間 18,716 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 292 ms
66,584 KB
testcase_01 AC 67 ms
35,584 KB
testcase_02 AC 67 ms
35,424 KB
testcase_03 AC 66 ms
35,584 KB
testcase_04 AC 69 ms
35,456 KB
testcase_05 AC 69 ms
35,456 KB
testcase_06 AC 368 ms
76,584 KB
testcase_07 AC 368 ms
76,456 KB
testcase_08 AC 362 ms
76,456 KB
testcase_09 AC 367 ms
76,436 KB
testcase_10 AC 370 ms
76,208 KB
testcase_11 AC 336 ms
66,260 KB
testcase_12 AC 335 ms
66,260 KB
testcase_13 AC 339 ms
66,004 KB
testcase_14 AC 337 ms
66,096 KB
testcase_15 AC 334 ms
66,108 KB
testcase_16 AC 335 ms
65,996 KB
testcase_17 AC 341 ms
66,012 KB
testcase_18 AC 342 ms
66,128 KB
testcase_19 AC 337 ms
66,108 KB
testcase_20 AC 339 ms
65,996 KB
testcase_21 AC 69 ms
35,584 KB
testcase_22 AC 69 ms
35,456 KB
testcase_23 AC 68 ms
191,888 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (96 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[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, q) = (c[0], c[1]);
        var a = NList;
        var query = NArr(q);
        var map = new List<int>[100001];
        for (var i = 1; i < map.Length; ++i) map[i] = new List<int>();
        for (var i = 0; i < n; ++i)
        {
            foreach (var p in PList(a[i])) map[p].Add(i);
        }
        var ans = new int[q];
        for (var i = 0; i < q; ++i)
        {
            var lpos = LowerBound(0, query[i][0] - 1, map[query[i][2]]);
            var rpos = LowerBound(0, query[i][1], map[query[i][2]]);
            ans[i] = rpos - lpos;
        }
        WriteLine(string.Join("\n", ans));
    }
    static List<int> PList(int a)
    {
        var ans = new List<int>();
        for (var i = 1; i * i <= a; ++i)
        {
            if (a % i == 0)
            {
                ans.Add(i);
                if (i * i < a) ans.Add(a / i);
            }
        }
        return ans;
    }
    static int LowerBound(int left, int min, IList<int> list)
    {
        if (left >= list.Count) return list.Count;
        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