結果
| 問題 |
No.854 公平なりんご分配
|
| コンテスト | |
| ユーザー |
cotton_fn_
|
| 提出日時 | 2019-07-26 22:34:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,260 bytes |
| コンパイル時間 | 1,728 ms |
| コンパイル使用メモリ | 122,472 KB |
| 最終ジャッジ日時 | 2025-01-07 08:13:51 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 MLE * 1 |
| other | AC * 29 TLE * 4 MLE * 59 |
ソースコード
#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
template<class T, class F = plus<T>>
struct Fenwick {
i64 n;
vector<T> c;
F f;
Fenwick(i64 n, F f = plus<T>(), T init = T())
: n(n), c(n + 1, init), f(f) {}
T sum(i64 i) {
return i > 0 ? f(sum(i - (i & -i)), c[i]) : T();
}
void add(i64 i, i64 x) {
if (i <= n) {
c[i] = f(c[i], x);
add(i + (i & -i), x);
}
}
};
template<class T, class F>
Fenwick<T, F> make_fenwick(i64 n, F f, T init = T()) {
return Fenwick<T, F>(n, f, init);
}
i64 n;
// 315,000,000
vector<Fenwick<unsigned short>> fs;
int main() {
cin >> n;
init_n(fs, 100001,
make_fenwick(n, plus<unsigned short>(), (unsigned short)0));
for (i64 i = 1; i <= n; ++i) {
i64 a; cin >> a;
for (i64 x = 2; x <= 330; ++x) {
while (a % x == 0) {
fs[x].add(i, 1);
a /= x;
}
}
if (a > 1) fs[a].add(i, 1);
}
i64 q;
cin >> q;
while (q--) {
i64 p, l, r;
cin >> p >> l >> r;
if (p == 1) {
cout << "Yes\n";
continue;
}
map<i64, i64> mp;
for (int x = 2; x <= 330; ++x) {
while (p % x == 0) {
mp[x]++;
p /= x;
}
}
if (p > 1) mp[p]++;
bool ok = true;
for (auto e : mp) {
i64 x = e.first, c = e.second;
i64 s = fs[x].sum(r) - fs[x].sum(l - 1);
if (c > s) ok = false;
}
cout << (ok ? "Yes" : "NO") << '\n';
}
return 0;
}
cotton_fn_