結果
問題 | No.854 公平なりんご分配 |
ユーザー | ei1333333 |
提出日時 | 2019-07-26 22:19:11 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 724 ms / 3,153 ms |
コード長 | 4,118 bytes |
コンパイル時間 | 2,091 ms |
コンパイル使用メモリ | 214,668 KB |
実行使用メモリ | 123,648 KB |
最終ジャッジ日時 | 2024-07-02 07:41:26 |
合計ジャッジ時間 | 12,654 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 4 ms
6,944 KB |
testcase_23 | AC | 3 ms
6,944 KB |
testcase_24 | AC | 4 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,944 KB |
testcase_26 | AC | 4 ms
6,940 KB |
testcase_27 | AC | 4 ms
6,944 KB |
testcase_28 | AC | 3 ms
6,940 KB |
testcase_29 | AC | 3 ms
6,944 KB |
testcase_30 | AC | 3 ms
6,944 KB |
testcase_31 | AC | 4 ms
6,940 KB |
testcase_32 | AC | 41 ms
28,672 KB |
testcase_33 | AC | 41 ms
16,896 KB |
testcase_34 | AC | 79 ms
38,144 KB |
testcase_35 | AC | 56 ms
30,720 KB |
testcase_36 | AC | 36 ms
6,940 KB |
testcase_37 | AC | 39 ms
27,136 KB |
testcase_38 | AC | 31 ms
22,528 KB |
testcase_39 | AC | 116 ms
40,448 KB |
testcase_40 | AC | 46 ms
14,848 KB |
testcase_41 | AC | 53 ms
25,216 KB |
testcase_42 | AC | 70 ms
37,504 KB |
testcase_43 | AC | 85 ms
26,240 KB |
testcase_44 | AC | 89 ms
35,072 KB |
testcase_45 | AC | 80 ms
9,344 KB |
testcase_46 | AC | 107 ms
34,688 KB |
testcase_47 | AC | 43 ms
20,608 KB |
testcase_48 | AC | 67 ms
36,992 KB |
testcase_49 | AC | 65 ms
37,888 KB |
testcase_50 | AC | 36 ms
26,880 KB |
testcase_51 | AC | 104 ms
36,224 KB |
testcase_52 | AC | 78 ms
17,536 KB |
testcase_53 | AC | 43 ms
17,280 KB |
testcase_54 | AC | 76 ms
20,224 KB |
testcase_55 | AC | 30 ms
17,408 KB |
testcase_56 | AC | 27 ms
18,048 KB |
testcase_57 | AC | 41 ms
15,232 KB |
testcase_58 | AC | 74 ms
8,064 KB |
testcase_59 | AC | 22 ms
13,696 KB |
testcase_60 | AC | 60 ms
15,104 KB |
testcase_61 | AC | 27 ms
6,940 KB |
testcase_62 | AC | 58 ms
13,312 KB |
testcase_63 | AC | 49 ms
13,824 KB |
testcase_64 | AC | 19 ms
7,296 KB |
testcase_65 | AC | 52 ms
33,280 KB |
testcase_66 | AC | 36 ms
10,752 KB |
testcase_67 | AC | 64 ms
22,528 KB |
testcase_68 | AC | 65 ms
11,392 KB |
testcase_69 | AC | 51 ms
40,448 KB |
testcase_70 | AC | 26 ms
14,976 KB |
testcase_71 | AC | 29 ms
16,000 KB |
testcase_72 | AC | 53 ms
6,944 KB |
testcase_73 | AC | 44 ms
27,392 KB |
testcase_74 | AC | 81 ms
32,896 KB |
testcase_75 | AC | 44 ms
16,256 KB |
testcase_76 | AC | 69 ms
26,240 KB |
testcase_77 | AC | 72 ms
36,992 KB |
testcase_78 | AC | 78 ms
12,416 KB |
testcase_79 | AC | 75 ms
23,168 KB |
testcase_80 | AC | 73 ms
24,192 KB |
testcase_81 | AC | 58 ms
25,216 KB |
testcase_82 | AC | 326 ms
123,648 KB |
testcase_83 | AC | 724 ms
123,520 KB |
testcase_84 | AC | 685 ms
123,520 KB |
testcase_85 | AC | 699 ms
123,520 KB |
testcase_86 | AC | 248 ms
123,520 KB |
testcase_87 | AC | 307 ms
123,520 KB |
testcase_88 | AC | 304 ms
123,520 KB |
testcase_89 | AC | 305 ms
123,520 KB |
testcase_90 | AC | 299 ms
123,520 KB |
testcase_91 | AC | 297 ms
123,648 KB |
testcase_92 | AC | 390 ms
123,520 KB |
testcase_93 | AC | 394 ms
123,648 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int mod = 1e9 + 7; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 > &p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template< typename T = int64 > vector< T > make_v(size_t a) { return vector< T >(a); } template< typename T, typename... Ts > auto make_v(size_t a, Ts... ts) { return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...)); } template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; } template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); } template< typename F > struct FixPoint : F { FixPoint(F &&f) : F(forward< F >(f)) {} template< typename... Args > decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, forward< Args >(args)...); } }; template< typename F > inline decltype(auto) MFP(F &&f) { return FixPoint< F >{forward< F >(f)}; } std::vector< int > eratosthenes_sieve(int n) { std::vector< int > ps(n + 1); std::iota(ps.begin() + 2, ps.end(), 2); for(int i = 2; i * i <= n; ++i) if(ps[i]) for(int j = i * i; j <= n; j += i) ps[j] = 0; return ps; } std::vector< int > make_primes(int n) { std::vector< int > ps = eratosthenes_sieve(n); ps.erase(std::remove(ps.begin(), ps.end(), 0), ps.end()); return ps; } std::pair< std::vector< int64 >, std::vector< int64 > > prime_factor_decomp_fast(int64 n) { static const auto ps = make_primes(2000); // sqrt(10^9) std::vector< int64 > p, e; int64 m = n; for(auto &i : ps) { if(i * i > n) break; if(m % i != 0) continue; int c = 0; while(m % i == 0) c++, m /= i; p.push_back(i); e.push_back(c); } if(m > 1) { p.push_back(m); e.push_back(1); } return std::make_pair(p, e); } int main() { int N; cin >> N; vector< int64 > A(N); cin >> A; vector< int > zero(N + 1); auto ret = make_primes(2001); vector< int > id(2020, -1); int ptr = 0; for(auto &p : ret) id[p] = ptr++; vector< vector< int > > sum(ret.size(), vector< int >(N + 1)); for(int i = 0; i < N; i++) { if(A[i] == 0) { zero[i + 1]++; } else { auto p = prime_factor_decomp_fast(A[i]); for(int j = 0; j < p.first.size(); j++) { sum[id[p.first[j]]][i + 1] += p.second[j]; } } } for(int i = 1; i <= N; i++) { zero[i] += zero[i - 1]; } for(auto &vs : sum) { for(int i = 1; i < vs.size(); i++) vs[i] += vs[i - 1]; } int Q; cin >> Q; for(int i = 0; i < Q; i++) { int p, l, r; cin >> p >> l >> r; --l; if(p == 1 || zero[r] - zero[l]) { cout << "Yes" << endl; continue; } auto tap = prime_factor_decomp_fast(p); bool flag = true; for(int j = tap.first.size() - 1; j >= 0 && flag; j--) { if(tap.first[j] > 2000) { flag = false; } else { auto &vs = sum[id[tap.first[j]]]; flag &= vs[r] - vs[l] >= tap.second[j]; } } if(flag) cout << "Yes" << endl; else cout << "NO" << endl; } }