結果

問題 No.854 公平なりんご分配
ユーザー kibunakibuna
提出日時 2019-07-26 22:25:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,162 bytes
コンパイル時間 1,711 ms
コンパイル使用メモリ 176,384 KB
実行使用メモリ 814,608 KB
最終ジャッジ日時 2023-09-15 02:10:35
合計ジャッジ時間 43,847 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 RE -
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 RE -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 RE -
testcase_23 AC 15 ms
6,092 KB
testcase_24 AC 39 ms
9,216 KB
testcase_25 AC 12 ms
5,188 KB
testcase_26 AC 40 ms
9,508 KB
testcase_27 AC 28 ms
9,420 KB
testcase_28 RE -
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 12 ms
5,376 KB
testcase_31 AC 34 ms
8,436 KB
testcase_32 AC 1,077 ms
289,276 KB
testcase_33 AC 902 ms
145,544 KB
testcase_34 MLE -
testcase_35 AC 1,340 ms
311,196 KB
testcase_36 RE -
testcase_37 AC 981 ms
268,064 KB
testcase_38 AC 761 ms
215,916 KB
testcase_39 MLE -
testcase_40 RE -
testcase_41 AC 1,259 ms
247,508 KB
testcase_42 MLE -
testcase_43 RE -
testcase_44 MLE -
testcase_45 RE -
testcase_46 RE -
testcase_47 AC 963 ms
194,948 KB
testcase_48 MLE -
testcase_49 MLE -
testcase_50 AC 929 ms
266,060 KB
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 WA -
testcase_56 WA -
testcase_57 RE -
testcase_58 RE -
testcase_59 WA -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 MLE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 MLE -
testcase_70 WA -
testcase_71 WA -
testcase_72 RE -
testcase_73 WA -
testcase_74 MLE -
testcase_75 RE -
testcase_76 RE -
testcase_77 MLE -
testcase_78 RE -
testcase_79 RE -
testcase_80 RE -
testcase_81 WA -
testcase_82 MLE -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

template <typename T = int>
void primeFactors(T a, map<T, int> &facs) {
    double sqrtA = sqrt(a);
    for (int i = 2; i <= sqrtA + 1e-10; ++i) {
        while (a % i == 0) {
            facs[i]++;
            a /= i;
        }
    }
    if (a > sqrtA)
        facs[a]++;
    return;
}

template <typename T = int>
void primeFactorsP(T a, map<T, int> &facs) {
    for (int i = 2; i <= 2000; ++i) { // don't check p > 2000
        while (a % i == 0) {
            facs[i]++;
            a /= i;
        }
    }
    if (a > 1)
        facs[a]++;
    return;
}

int main() {
    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int q;
    cin >> q;
    vi p(n), l(n), r(n);
    for (int i = 0; i < q; ++i) {
        cin >> p[i] >> l[i] >> r[i];
        l[i]--;
        r[i]--;
    }

    vector<map<int, int>> facs(n);
    for (int i = 0; i < n; ++i) {
        primeFactors(a[i], facs[i]);
    }
    for (int i = 0; i < n - 1; ++i) {
        for (auto &ff : facs[i]) {
            facs[i + 1][ff.first] += ff.second;
        }
    }
    for (int i = 0; i < q; ++i) {
        map<int, int> facsToUse = facs[r[i]];
        if (l[i] > 0) {
            for (auto &ff : facs[l[i] - 1]) {
                facsToUse[ff.first] -= ff.second;
            }
        }
        map<int, int> pprimes;
        primeFactorsP(p[i], pprimes);
        bool ok = true;
        for (auto &pp : pprimes) {
            if (facsToUse[pp.first] < pp.second) {
                ok = false;
                break;
            }
        }
        if (ok)
            cout << "Yes"
                 << "\n";
        else
            cout << "NO"
                 << "\n";
    }

    return 0;
}
0