結果
| 問題 |
No.2758 RDQ
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2024-10-10 20:28:21 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 1,081 ms / 2,000 ms |
| コード長 | 5,113 bytes |
| コンパイル時間 | 15,436 ms |
| コンパイル使用メモリ | 171,008 KB |
| 実行使用メモリ | 189,676 KB |
| 最終ジャッジ日時 | 2024-10-10 20:28:54 |
| 合計ジャッジ時間 | 27,075 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (98 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/
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
// https://yukicoder.me/problems/no/2758
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("5 3");
WillReturn.Add("2 6 7 19 14");
WillReturn.Add("1 4 2");
WillReturn.Add("3 5 4");
WillReturn.Add("1 5 7");
//2
//0
//2
}
else if (InputPattern == "Input2") {
WillReturn.Add("5 4");
WillReturn.Add("7 6 5 4 3");
WillReturn.Add("1 5 2");
WillReturn.Add("2 3 3");
WillReturn.Add("2 4 4");
WillReturn.Add("1 3 5");
//2
//1
//1
//1
}
else if (InputPattern == "Input3") {
WillReturn.Add("3 1");
WillReturn.Add("1000 1000 100");
WillReturn.Add("1 3 10");
//3
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
long[] AArr = InputList[1].Split(' ').Select(pX => long.Parse(pX)).ToArray();
// IndのList[Aの約数]なDict
var IndListDict = new Dictionary<long, List<long>>();
for (long I = 0; I <= AArr.GetUpperBound(0); I++) {
long[] YakusuuArr = DeriveYakusuuArr(AArr[I]);
foreach (long EachYakuu in YakusuuArr) {
if (IndListDict.ContainsKey(EachYakuu) == false) {
IndListDict[EachYakuu] = new List<long>();
}
IndListDict[EachYakuu].Add(I);
}
}
long[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray();
foreach (string EachStr in InputList.Skip(2)) {
SplitAct(EachStr);
long RangeSta = wkArr[0] - 1;
long RangeEnd = wkArr[1] - 1;
long K = wkArr[2];
if (IndListDict.ContainsKey(K) == false) {
Console.WriteLine(0);
}
else {
long Answer = GetListRangeValueCnt.GetCnt(IndListDict[K], RangeSta, RangeEnd);
Console.WriteLine(Answer);
}
}
}
// 約数を列挙する
static long[] DeriveYakusuuArr(long pTarget)
{
var YakusuuSet = new HashSet<long>();
for (long I = 1; I * I <= pTarget; I++) {
if (pTarget % I == 0) {
YakusuuSet.Add(I);
YakusuuSet.Add(pTarget / I);
}
}
long[] YakusuuArr = YakusuuSet.ToArray();
Array.Sort(YakusuuArr);
return YakusuuArr;
}
}
#region GetListRangeValueCnt
// 昇順にソートされたList、Min,Maxを引数とし、
// Min以上Max以下な値の個数を返す
internal class GetListRangeValueCnt
{
static internal long GetCnt(List<long> pSortedList, long pMinVal, long pMaxVal)
{
if (pMinVal > pMaxVal) {
throw new Exception("pMinVal > pMaxVal");
}
int ResultInd1 = ExecNibunhou_LowerBound(pMinVal, pSortedList);
int ResultInd2 = ExecNibunhou_LowerOrEqual_Max(pMaxVal, pSortedList);
if (ResultInd1 == -1 || ResultInd2 == -1) return 0;
return ResultInd2 - ResultInd1 + 1;
}
// 二分法で、Val以上で最小の値を持つ、添字を返す
static int ExecNibunhou_LowerBound(long pVal, List<long> pList)
{
if (pList.Count == 0) return -1;
// 最後の要素がVal未満の特殊ケース
if (pVal > pList[pList.Count - 1]) {
return -1;
}
// 最初の要素がVal以上の特殊ケース
if (pVal <= pList[0]) {
return 0;
}
int L = 0;
int R = pList.Count - 1;
while (L + 1 < R) {
int Mid = (L + R) / 2;
if (pList[Mid] >= pVal) {
R = Mid;
}
else {
L = Mid;
}
}
return R;
}
// 二分法で、Val以下で最大の値を持つ、添字を返す
static int ExecNibunhou_LowerOrEqual_Max(long pVal, List<long> pList)
{
if (pList.Count == 0) return -1;
// 最後の要素がVal以下の特殊ケース
if (pVal >= pList[pList.Count - 1]) {
return pList.Count - 1;
}
// 最初の要素がVal超えの特殊ケース
if (pVal < pList[0]) {
return -1;
}
int L = 0;
int R = pList.Count - 1;
while (L + 1 < R) {
int Mid = (L + R) / 2;
if (pList[Mid] <= pVal) {
L = Mid;
}
else {
R = Mid;
}
}
return L;
}
}
#endregion
aketijyuuzou