結果
| 問題 |
No.2758 RDQ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-26 03:05:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,133 bytes |
| コンパイル時間 | 2,603 ms |
| コンパイル使用メモリ | 212,140 KB |
| 最終ジャッジ日時 | 2025-02-21 16:40:23 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | MLE * 1 -- * 20 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/segtree>
using namespace std;
using namespace atcoder;
using ll=long long;
using S=ll;
S op(S a,S b){return a+b;}
S e(){return 0;}
vector<long long> calc_divisors(long long N) {
vector<long long> res;
for (long long 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.push_back(j);
}
}
sort(vs.begin(),vs.end());
vs.erase(unique(vs.begin(),vs.end()),vs.end());
map<ll,ll> rev;
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;
}
}