結果
| 問題 |
No.854 公平なりんご分配
|
| コンテスト | |
| ユーザー |
cotton_fn_
|
| 提出日時 | 2019-07-27 04:30:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,342 bytes |
| コンパイル時間 | 1,290 ms |
| コンパイル使用メモリ | 130,076 KB |
| 最終ジャッジ日時 | 2025-01-07 09:34:31 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 WA * 68 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x)
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs
i64 n;
vector<array<int, 100001>> fs;
vector<int> zs;
int main() {
cin >> n;
vector<bool> serve(2001, true);
for (int x = 2; x <= 2000; ++x) {
if (serve[x]) {
for (int y = 2 * x; y <= 2000; y += x) serve[y] = false;
}
}
map<int, int> pmp, ipmp;
for (int x = 2; x <= 2000; ++x) {
if (serve[x]) {
pmp[x] = pmp.size() + 1;
ipmp[pmp.size()] = x;
}
}
init_n(fs, 401);
init_n(zs, n + 1);
for (i64 i = 1; i <= n; ++i) {
i64 a; cin >> a;
if (a == 0) {
zs[i]++;
continue;
}
for (i64 x = 2; x <= 40; ++x) {
while (a % x == 0) {
fs[pmp[x]][i]++;
a /= x;
}
}
if (a > 1) fs[pmp[a]][i]++;
}
for (int k = 0; k <= 400; ++k) {
for (int i = 1; i <= n; ++i) {
fs[k][i] += fs[k][i - 1];
}
}
for (int i = 1; i <= n; ++i) zs[i] += zs[i - 1];
i64 q;
cin >> q;
while (q--) {
i64 p, l, r;
cin >> p >> l >> r;
if (p == 1) {
cout << "Yes\n";
continue;
}
if (zs[r] - zs[l - 1] > 0) {
cout << "NO\n";
continue;
}
map<i64, i64> mp;
for (int i = 1; i <= ipmp.size(); ++i) {
i64 x = ipmp[i];
while (p % x == 0) {
mp[i]++;
p /= x;
}
}
bool ok = true;
for (auto e : mp) {
i64 i = e.first, c = e.second;
i64 s = fs[i][r] - fs[i][l - 1];
if (c > s) ok = false;
}
cout << (ok ? "Yes" : "NO") << '\n';
}
return 0;
}
cotton_fn_