結果
問題 | No.2758 RDQ |
ユーザー |
![]() |
提出日時 | 2024-05-26 00:08:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 433 ms / 2,000 ms |
コード長 | 808 bytes |
コンパイル時間 | 859 ms |
コンパイル使用メモリ | 88,488 KB |
最終ジャッジ日時 | 2025-02-21 16:39:29 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <iostream>#include <cassert>#include <vector>#include <map>#include <algorithm>using namespace std;int main() {int N, Q; cin >> N >> Q;map<int, vector<int>> mp;for (int i = 0; i < N; i++) {int a; cin >> a;for (int j = 1; j * j <= a; j++) {if (a % j == 0) {mp[j].push_back(i);if (a / j != j) {mp[a / j].push_back(i);}}}}while (Q--) {int l, r, k;cin >> l >> r >> k;l--; r--;int lidx = lower_bound(mp[k].begin(), mp[k].end(), l) - mp[k].begin();if (lidx == mp[k].size()) {cout << 0 << endl;continue;}int ridx = lower_bound(mp[k].begin(), mp[k].end(), r) - mp[k].begin();if (ridx == mp[k].size() || mp[k][ridx] > r) ridx--;cout << ridx - lidx + 1 << endl;}return 0;}