結果
問題 |
No.2758 RDQ
|
ユーザー |
|
提出日時 | 2024-05-05 13:06:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 446 ms / 2,000 ms |
コード長 | 861 bytes |
コンパイル時間 | 890 ms |
コンパイル使用メモリ | 86,452 KB |
実行使用メモリ | 15,104 KB |
最終ジャッジ日時 | 2024-12-20 15:35:07 |
合計ジャッジ時間 | 8,940 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <map> #define rep(i,n) for(ll i = 0; i < n; i++) //[0,n) #define all(A) (A).begin(),(A).end() using namespace std; using ll = long long; template <class T> int siz(T& a){return (int)a.size();} vector<int> divisors(int x){ vector<int> res; for(ll i = 1; i*i <= x; i++){ if(x%i != 0) continue; res.push_back(i); if(x/i != i) res.push_back(x/i); } return res; } int main(){ int N,Q; cin >> N >> Q; vector<int> A(N); rep(i,N) cin >> A[i]; map<int,vector<int>> mp; rep(i,N){ auto D = divisors(A[i]); for(int r : D) mp[r].push_back(i); } rep(i,Q){ int L,R,K; cin >> L >> R >> K; L--; R--; auto cnt = upper_bound(all(mp[K]),R)-lower_bound(all(mp[K]),L); cout << cnt << endl; } }