結果
問題 |
No.2758 RDQ
|
ユーザー |
|
提出日時 | 2024-05-26 13:10:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,142 bytes |
コンパイル時間 | 2,506 ms |
コンパイル使用メモリ | 211,268 KB |
最終ジャッジ日時 | 2025-02-21 16:44:49 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | MLE * 1 -- * 20 |
ソースコード
#include<bits/stdc++.h> #include<atcoder/segtree> using namespace std; using namespace atcoder; using ll=int; using S=ll; S op(S a,S b){return a+b;} S e(){return 0;} vector<ll> calc_divisors(ll N) { vector<ll> res; for (ll i = 1; i * i <= N; ++i) { if (N % i != 0) continue; res.push_back(i); if (N / i != i) res.push_back(N / i); } sort(res.begin(), res.end()); return res; } int main(){ ll n,q; cin>>n>>q; vector<ll> a(n); for(ll i=0;i<n;i++){ cin>>a[i]; } vector<ll> vs; for(ll i=0;i<n;i++){ vector<ll> d=calc_divisors(a[i]); for(ll j:d){ vs.emplace_back(j); } } sort(vs.begin(),vs.end()); vs.erase(unique(vs.begin(),vs.end()),vs.end()); unordered_map<ll,ll> rev; rev.reserve((ll)vs.size()); for(ll i=0;i<(ll)vs.size();i++){ rev[vs[i]]=i+1; } segtree<S,op,e> seg_(n); vector<segtree<S,op,e>> seg((ll)vs.size()+1,seg_); for(ll i=0;i<n;i++){ vector<ll> d=calc_divisors(a[i]); for(ll j:d){ seg[rev[j]].set(i,1); } } while(q--){ ll l,r,k; cin>>l>>r>>k; l--; cout<<seg[rev[k]].prod(l,r)<<endl; } }