結果
| 問題 |
No.854 公平なりんご分配
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2019-07-26 22:13:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 963 ms / 3,153 ms |
| コード長 | 1,753 bytes |
| コンパイル時間 | 1,870 ms |
| コンパイル使用メモリ | 182,988 KB |
| 実行使用メモリ | 122,476 KB |
| 最終ジャッジ日時 | 2024-07-02 07:37:07 |
| 合計ジャッジ時間 | 10,127 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 92 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
V<> sieve(int n) {
V<bool> b((n + 1) / 3, true);
V<> res{2, 3};
for (int p = 5, d = 2; p * p < n; p += d, d = 6 - d) if (b[p / 3]) {
for (int i = 5 * p, d = 2 * p; i < n; i += d, d = 6 * p - d) b[i / 3] = false;
}
for (int p = 5, d = 2; p < n; p += d, d = 6 - d) if(b[p / 3]) res.push_back(p);
while (!res.empty() and res.back() >= n) res.pop_back();
return res;
}
template<class Z> map<Z, int> factorize(Z n) {
map<Z, int> res;
for (Z i = 2; i * i <= n; ++i) while (n % i == 0) ++res[i], n /= i;
if (n != 1) ++res[n];
return res;
}
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
int n; cin >> n;
V<> p2i(2000);
{
auto ps = sieve(2000);
for (int i = 0; i < 303; ++i) {
p2i[ps[i]] = i;
}
}
VV<> a(303, V<>(n + 1));
V<> z(n + 1);
for (int i = 0; i < n; ++i) {
int x; cin >> x;
if (!x) {
z[i] = 1;
continue;
}
for (const auto& e : factorize(x)) {
a[p2i[e.first]][i] = e.second;
}
}
for (auto&& v : a) {
for (int i = n - 1; i >= 0; --i) v[i] += v[i + 1];
}
for (int i = n - 1; i >= 0; --i) z[i] += z[i + 1];
int q; cin >> q;
while (q--) {
int p, l, r; cin >> p >> l >> r, --l;
if (z[l] - z[r]) cout << "Yes" << '\n';
else {
bool ok = true;
for (const auto& e : factorize(p)) {
if (e.first > 2000) {
ok = false;
break;
}
int i = p2i[e.first];
if (e.second > a[i][l] - a[i][r]) {
ok = false;
break;
}
}
cout << (ok ? "Yes" : "NO") << '\n';
}
}
}
risujiroh