結果

問題 No.2758 RDQ
ユーザー 👑 chro_96chro_96
提出日時 2024-05-17 22:16:18
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,365 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 30,848 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-17 23:45:28
合計ジャッジ時間 2,460 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 54 ms
6,940 KB
testcase_07 AC 52 ms
6,944 KB
testcase_08 AC 54 ms
6,944 KB
testcase_09 AC 51 ms
6,944 KB
testcase_10 AC 51 ms
6,944 KB
testcase_11 AC 71 ms
6,940 KB
testcase_12 AC 73 ms
6,940 KB
testcase_13 AC 70 ms
6,940 KB
testcase_14 AC 71 ms
6,944 KB
testcase_15 AC 70 ms
6,940 KB
testcase_16 AC 70 ms
6,940 KB
testcase_17 AC 73 ms
6,944 KB
testcase_18 AC 71 ms
6,944 KB
testcase_19 AC 69 ms
6,940 KB
testcase_20 AC 71 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int cmp_int (const void *ap, const void *bp) {
  int a = *(int *)ap;
  int b = *(int *)bp;
  
  if (a < b) {
    return -1;
  }
  
  if (a > b) {
    return 1;
  }
  
  return 0;
}

int main () {
  int n = 0;
  int q = 0;
  int a[50000] = {};
  int l[50000][2] = {};
  int r[50000][2] = {};
  int k[50000] = {};
  
  int res = 0;
  
  int ans[50000][2] = {};
  
  int idx1 = 0;
  int idx2 = 0;
  
  int cnt[100000] = {};
  
  res = scanf("%d", &n);
  res = scanf("%d", &q);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", a+i);
  }
  for (int i = 0; i < q; i++) {
    res = scanf("%d", l[i]);
    res = scanf("%d", r[i]);
    res = scanf("%d", k+i);
    l[i][0]--;
    l[i][1] = i;
    r[i][0]--;
    r[i][1] = i;
  }
  
  qsort(l, q, sizeof(int)*2, cmp_int);
  qsort(r, q, sizeof(int)*2, cmp_int);
  
  for (int i = 0; i < n; i++) {
    while (idx1 < q && l[idx1][0] <= i) {
      ans[l[idx1][1]][0] = cnt[k[l[idx1][1]]-1];
      idx1++;
    }
    for (int p = 1; p*p <= a[i]; p++) {
      if (a[i]%p == 0) {
        cnt[p-1]++;
        if (p*p != a[i]) {
          cnt[a[i]/p-1]++;
        }
      }
    }
    while (idx2 < q && r[idx2][0] <= i) {
      ans[r[idx2][1]][1] = cnt[k[r[idx2][1]]-1];
      idx2++;
    }
  }
  
  for (int i = 0; i < q; i++) {
    printf("%d\n", ans[i][1]-ans[i][0]);
  }
  
  return 0;
}
0