結果

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll N, Q, A;
    cin >> N >> Q;
    vector<vector<ll>> fac(1e5+1), v(1e5+1);
    for (int i=1; i<=1e5; i++){
        for (int j=i; j<=1e5; j+=i){
            fac[j].push_back(i);
        }
    }

    for (int i=1; i<=N; i++){
        cin >> A;
        for (auto x : fac[A]){
            v[x].push_back(i);
        }
    }

    while(Q--){
        ll L, R, K;
        cin >> L >> R >> K;
        cout << upper_bound(v[K].begin(), v[K].end(), R)-lower_bound(v[K].begin(), v[K].end(), L) << endl;
    }

    return 0;
}
0