結果

問題 No.2758 RDQ
ユーザー eve__fuyuki
提出日時 2024-05-17 21:26:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 827 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 198,164 KB
最終ジャッジ日時 2025-02-21 14:30:24
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main() {
    fast_io();
    int n, q;
    cin >> n >> q;
    const int M = 1e5;
    vector<int> a(n);
    vector<vector<int>> idx(M + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 1; j * j <= a[i]; j++) {
            if (a[i] % j == 0) {
                idx[j].push_back(i);
                if (j * j != a[i]) {
                    idx[a[i] / j].push_back(i);
                }
            }
        }
    }
    for (; q--;) {
        int l, r, k;
        cin >> l >> r >> k;
        l--;
        auto lb = lower_bound(idx[k].begin(), idx[k].end(), l);
        auto ub = upper_bound(idx[k].begin(), idx[k].end(), r - 1);
        cout << ub - lb << "\n";
    }
}
0