結果
問題 | No.854 公平なりんご分配 |
ユーザー |
![]() |
提出日時 | 2019-07-26 23:00:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 405 ms / 3,153 ms |
コード長 | 1,489 bytes |
コンパイル時間 | 634 ms |
コンパイル使用メモリ | 77,088 KB |
実行使用メモリ | 121,936 KB |
最終ジャッジ日時 | 2024-07-02 08:59:48 |
合計ジャッジ時間 | 10,005 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 92 |
ソースコード
#include <algorithm>#include <cassert>#include <vector>#include <iostream>using namespace std;int B[100100][303] = {};int main() {vector<int> ps;vector<bool> b(2001);fill(b.begin(), b.end(), true);for (int p = 2; p < 2000; p++)if (b[p]) {ps.push_back(p);for (int q = p*p; q < 2000; q += p) b[q] = false;}assert(ps.size() == 303);int n; cin >> n;vector<int> zpos;for (int i = 0; i < n; i++) {int a; cin >> a;if (a == 0) { zpos.push_back(i+1); continue; }elsefor (int k = 0; k < ps.size() && a > 1; k++) {int p = ps[k], e = 0;while (a % p == 0) { e++; a /= p; }if (e > 0)for (int j = i+1; j <= n; j += j&-j) B[j][k] += e;}}int q; cin >> q;while (q--) {int l, r, x; cin >> x >> l >> r;auto it = lower_bound(zpos.begin(), zpos.end(), l);if (it != zpos.end() && *it <= r) cout << "Yes" << endl;else {for (int k = 0; k < ps.size(); k++) {int p = ps[k], e = 0;if (x % p == 0) {for (int j = r; j > 0; j -= j&-j) e += B[j][k];for (int j = l-1; j > 0; j -= j&-j) e -= B[j][k];while (e > 0 && x % p == 0) x /= p, e--;}}cout << (x == 1 ? "Yes" : "NO") << endl;}}}