結果

問題 No.854 公平なりんご分配
ユーザー firiexpfiriexp
提出日時 2019-12-31 06:25:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 341 ms / 3,153 ms
コード長 2,858 bytes
コンパイル時間 924 ms
コンパイル使用メモリ 105,772 KB
実行使用メモリ 126,592 KB
最終ジャッジ日時 2024-04-29 00:46:53
合計ジャッジ時間 10,134 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 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 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 2 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,944 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 3 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 4 ms
6,944 KB
testcase_32 AC 39 ms
29,440 KB
testcase_33 AC 34 ms
17,340 KB
testcase_34 AC 70 ms
39,296 KB
testcase_35 AC 50 ms
31,616 KB
testcase_36 AC 23 ms
6,944 KB
testcase_37 AC 37 ms
27,776 KB
testcase_38 AC 31 ms
23,168 KB
testcase_39 AC 99 ms
41,472 KB
testcase_40 AC 37 ms
15,232 KB
testcase_41 AC 46 ms
26,112 KB
testcase_42 AC 65 ms
38,528 KB
testcase_43 AC 66 ms
27,008 KB
testcase_44 AC 74 ms
35,968 KB
testcase_45 AC 55 ms
9,728 KB
testcase_46 AC 88 ms
35,584 KB
testcase_47 AC 36 ms
21,248 KB
testcase_48 AC 59 ms
38,144 KB
testcase_49 AC 57 ms
38,912 KB
testcase_50 AC 35 ms
27,648 KB
testcase_51 AC 89 ms
37,248 KB
testcase_52 AC 46 ms
18,100 KB
testcase_53 AC 30 ms
17,792 KB
testcase_54 AC 51 ms
20,864 KB
testcase_55 AC 24 ms
17,932 KB
testcase_56 AC 23 ms
18,688 KB
testcase_57 AC 28 ms
15,852 KB
testcase_58 AC 46 ms
8,704 KB
testcase_59 AC 18 ms
14,168 KB
testcase_60 AC 34 ms
15,612 KB
testcase_61 AC 14 ms
6,940 KB
testcase_62 AC 39 ms
13,788 KB
testcase_63 AC 27 ms
14,444 KB
testcase_64 AC 11 ms
7,936 KB
testcase_65 AC 48 ms
34,304 KB
testcase_66 AC 22 ms
11,136 KB
testcase_67 AC 43 ms
23,168 KB
testcase_68 AC 33 ms
11,904 KB
testcase_69 AC 52 ms
41,600 KB
testcase_70 AC 20 ms
15,616 KB
testcase_71 AC 23 ms
16,496 KB
testcase_72 AC 31 ms
6,944 KB
testcase_73 AC 38 ms
28,160 KB
testcase_74 AC 59 ms
33,792 KB
testcase_75 AC 30 ms
16,768 KB
testcase_76 AC 44 ms
26,752 KB
testcase_77 AC 58 ms
37,760 KB
testcase_78 AC 49 ms
12,928 KB
testcase_79 AC 49 ms
23,680 KB
testcase_80 AC 48 ms
24,960 KB
testcase_81 AC 38 ms
25,856 KB
testcase_82 AC 188 ms
126,464 KB
testcase_83 AC 315 ms
126,592 KB
testcase_84 AC 307 ms
126,592 KB
testcase_85 AC 338 ms
126,464 KB
testcase_86 AC 125 ms
126,464 KB
testcase_87 AC 199 ms
126,592 KB
testcase_88 AC 213 ms
126,336 KB
testcase_89 AC 193 ms
126,464 KB
testcase_90 AC 196 ms
126,592 KB
testcase_91 AC 197 ms
126,464 KB
testcase_92 AC 341 ms
126,464 KB
testcase_93 AC 339 ms
126,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <limits>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

using u32 = uint32_t;

template<typename T>
struct ExactDiv {
    T t, i, val;
    ExactDiv() {}
    ExactDiv(T n) : t(T(-1) / n), i(mul_inv(n)) , val(n) {};
    T mul_inv(T n) {
        T x = n;
        for (int i = 0; i < 5; ++i) x *= 2 - n * x;
        return x;
    }
    bool divide(T n) const {
        if(val == 2) return !(n & 1);
        return n * this->i <= this->t;
    }
};

vector<ExactDiv<u32>> get_prime(int n){
    if(n <= 1) return vector<ExactDiv<u32>>();
    vector<bool> is_prime(n+1, true);
    vector<ExactDiv<u32>> prime;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; ++i) {
        if(is_prime[i]) prime.emplace_back(i);
        for (auto &&j : prime){
            if(i*j.val > n) break;
            is_prime[i*j.val] = false;
            if(j.divide(i)) break;
        }
    }
    return prime;
}
const auto primes = get_prime(2000);

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int M = primes.size();
    int n;
    cin >> n;
    vector<int> zeros(n+1);
    auto v = make_v(n+1, M, 0);
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        zeros[i+1] = zeros[i] + (x == 0);
        if(x){
            for (int j = 0; j < M; ++j) {
                v[i+1][j] = v[i][j];
                while(primes[j].divide(x)){
                    v[i+1][j]++;
                    x /= primes[j].val;
                }
            }
        }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int p, l, r;
        scanf("%d %d %d", &p, &l, &r);
        l--;
        if(zeros[l] != zeros[r]) puts("Yes");
        else {
            int ok = 1;
            for (int j = 0; j < M && ok; ++j) {
                int cnt = v[r][j] - v[l][j];
                while(primes[j].divide(p)){
                    if(cnt == 0) {
                        ok = 0;
                        break;
                    }
                    p /= primes[j].val;
                    cnt--;
                }
            }
            puts(ok && p == 1 ? "Yes" : "NO");
        }
    }
    return 0;
}
0