結果
問題 |
No.2758 RDQ
|
ユーザー |
![]() |
提出日時 | 2024-05-22 11:57:21 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,367 bytes |
コンパイル時間 | 3,080 ms |
コンパイル使用メモリ | 80,356 KB |
実行使用メモリ | 334,888 KB |
最終ジャッジ日時 | 2024-12-20 18:24:55 |
合計ジャッジ時間 | 44,382 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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(); List<List<Integer>> current = new ArrayList<>(); for (int i = 0; i <= 100000; i++) { current.add(new ArrayList<>()); } for (int i = 1; i <= 100000; i++) { for (int j = 1; j * i <= 100000; j++) { current.get(j * i).add(i); } } Map<Integer, TreeMap<Integer, Integer>> places = new HashMap<>(); for (int i = 1; i <= n; i++) { int a = sc.nextInt(); for (int x : current.get(a)) { if (!places.containsKey(x)) { places.put(x, new TreeMap<>()); places.get(x).put(0, 0); } places.get(x).put(i, places.get(x).size()); } } StringBuilder sb = new StringBuilder(); while (q-- > 0) { int left = sc.nextInt(); int right = sc.nextInt(); int value = sc.nextInt(); if (!places.containsKey(value)) { sb.append("0\n"); continue; } sb.append(places.get(value).floorEntry(right).getValue() - places.get(value).lowerEntry(left).getValue()).append("\n"); } System.out.print(sb); } } 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(); } } }