結果
| 問題 |
No.2758 RDQ
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-05-22 11:24:59 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,548 bytes |
| コンパイル時間 | 2,732 ms |
| コンパイル使用メモリ | 84,104 KB |
| 実行使用メモリ | 345,360 KB |
| 最終ジャッジ日時 | 2024-12-20 18:22:58 |
| 合計ジャッジ時間 | 42,225 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 TLE * 5 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int q = sc.nextInt();
Map<Integer, TreeMap<Integer, Integer>> places = new HashMap<>();
for (int i = 1; i <= n; i++) {
int a = sc.nextInt();
for (int j = 1; j <= Math.sqrt(a); j++) {
if (a % j == 0) {
if (!places.containsKey(j)) {
places.put(j, new TreeMap<>());
places.get(j).put(0, 0);
}
places.get(j).put(i, places.get(j).size());
if (j * j < a) {
if (!places.containsKey(a / j)) {
places.put(a / j, new TreeMap<>());
places.get(a / j).put(0, 0);
}
places.get(a / j).put(i, places.get(a / j).size());
}
}
}
}
String result = IntStream.range(0, q).mapToObj(i -> getCount(places, sc.nextInt(), sc.nextInt(), sc.nextInt()))
.collect(Collectors.joining("\n"));
System.out.println(result);
}
static String getCount(Map<Integer, TreeMap<Integer, Integer>> places, int left, int right, int value) {
if (places.containsKey(value)) {
return String.valueOf(places.get(value).floorEntry(right).getValue() - places.get(value).lowerEntry(left).getValue());
} else {
return "0";
}
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
} catch (Exception e) {
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
try {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return st.nextToken();
}
}
}
tenten