結果

問題 No.854 公平なりんご分配
ユーザー yuji9511yuji9511
提出日時 2019-07-26 23:08:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 779 ms / 3,153 ms
コード長 3,271 bytes
コンパイル時間 1,583 ms
コンパイル使用メモリ 160,132 KB
実行使用メモリ 128,480 KB
最終ジャッジ日時 2023-09-15 04:05:36
合計ジャッジ時間 16,964 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,388 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 3 ms
5,392 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
5,436 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
5,308 KB
testcase_09 AC 3 ms
5,304 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
5,416 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,508 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,388 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,500 KB
testcase_22 AC 4 ms
5,664 KB
testcase_23 AC 4 ms
6,164 KB
testcase_24 AC 7 ms
6,584 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 7 ms
4,572 KB
testcase_27 AC 5 ms
4,504 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 3 ms
5,648 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 6 ms
4,508 KB
testcase_32 AC 71 ms
29,644 KB
testcase_33 AC 80 ms
19,368 KB
testcase_34 AC 148 ms
41,908 KB
testcase_35 AC 104 ms
31,708 KB
testcase_36 AC 59 ms
8,768 KB
testcase_37 AC 68 ms
31,588 KB
testcase_38 AC 49 ms
25,260 KB
testcase_39 AC 230 ms
44,116 KB
testcase_40 AC 93 ms
17,444 KB
testcase_41 AC 102 ms
27,776 KB
testcase_42 AC 130 ms
40,096 KB
testcase_43 AC 160 ms
29,560 KB
testcase_44 AC 168 ms
38,244 KB
testcase_45 AC 160 ms
11,548 KB
testcase_46 AC 221 ms
36,540 KB
testcase_47 AC 75 ms
21,408 KB
testcase_48 AC 119 ms
40,140 KB
testcase_49 AC 111 ms
40,016 KB
testcase_50 AC 59 ms
29,516 KB
testcase_51 AC 216 ms
38,444 KB
testcase_52 AC 127 ms
21,348 KB
testcase_53 AC 63 ms
19,444 KB
testcase_54 AC 127 ms
23,328 KB
testcase_55 AC 43 ms
19,552 KB
testcase_56 AC 39 ms
21,200 KB
testcase_57 AC 66 ms
19,176 KB
testcase_58 AC 132 ms
9,488 KB
testcase_59 AC 33 ms
15,244 KB
testcase_60 AC 87 ms
17,412 KB
testcase_61 AC 37 ms
6,964 KB
testcase_62 AC 109 ms
15,560 KB
testcase_63 AC 68 ms
15,464 KB
testcase_64 AC 27 ms
8,872 KB
testcase_65 AC 86 ms
37,724 KB
testcase_66 AC 60 ms
13,500 KB
testcase_67 AC 98 ms
23,720 KB
testcase_68 AC 96 ms
13,488 KB
testcase_69 AC 84 ms
44,040 KB
testcase_70 AC 36 ms
17,092 KB
testcase_71 AC 42 ms
17,316 KB
testcase_72 AC 80 ms
7,264 KB
testcase_73 AC 65 ms
31,428 KB
testcase_74 AC 132 ms
34,152 KB
testcase_75 AC 67 ms
17,424 KB
testcase_76 AC 96 ms
27,920 KB
testcase_77 AC 112 ms
38,256 KB
testcase_78 AC 137 ms
13,956 KB
testcase_79 AC 122 ms
25,972 KB
testcase_80 AC 117 ms
25,892 KB
testcase_81 AC 83 ms
27,952 KB
testcase_82 AC 412 ms
128,288 KB
testcase_83 AC 757 ms
128,380 KB
testcase_84 AC 744 ms
128,304 KB
testcase_85 AC 504 ms
128,252 KB
testcase_86 AC 548 ms
128,244 KB
testcase_87 AC 416 ms
128,380 KB
testcase_88 AC 415 ms
128,312 KB
testcase_89 AC 412 ms
128,480 KB
testcase_90 AC 414 ms
128,248 KB
testcase_91 AC 414 ms
128,324 KB
testcase_92 AC 779 ms
128,252 KB
testcase_93 AC 778 ms
128,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int sum[100010][310] = {};
ll is_zero[100010] = {};
struct Integer{
public:
    Integer(ll n){
    }

    ll gcd(ll a,ll b){return b ? gcd(b, a % b) : a;} //最大公約数

    ll lcm(ll a,ll b){return a / gcd(a, b) * b;} //最小公倍数

    bool isPrime(ll x){
        if(x < 2) return false;
        if(x == 2) return true;
        if(x % 2 == 0) return false;
        for(ll i = 3;i <= sqrt(x) + 1;i += 2) if(x % i == 0) return false;
        return true;
    }

    vector<ll> divisor(ll M){ //約数の全列挙
        vector<ll> dd;
        for(ll i = 1; i * i <= M; i++){
            if(M % i == 0){
                dd.push_back(i);
                if(i * i != M){
                    dd.push_back(M / i);
                }
            }
        }
        sort(dd.begin(), dd.end());
        return dd;
    }

    vector<ll> factor(ll M){ //素因数分解
        vector<ll> dd;
        if(M == 1){
            dd.push_back(1);
            return dd;
        }
        for(ll i = 2; i*i <= M; i++){
            while(M % i == 0){
                dd.push_back(i);
                M /= i;
            }
        }
        if(M != 1) dd.push_back(M);
        sort(dd.begin(), dd.end());
        return dd;
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[100010];
    rep(i,0,N) cin >> A[i];
    ll Q;
    cin >> Q;
    ll P[100010], L[100010], R[100010];
    rep(i,0,Q){
        cin >> P[i] >> L[i] >> R[i];
        L[i]--; R[i]--;
    }
    Integer it(0);
    vector<ll> prime;
    // prime.push_back(1);
    rep(i,2,2001){
        if(it.isPrime(i)) prime.push_back(i);
    }
    map<ll, ll> idx;
    rep(i,0,prime.size()){
        idx[prime[i]] = i;
    }
    rep(i,0,N){
        if(A[i] == 1 || A[i] == 0) continue;
        vector<ll> dd = it.factor(A[i]);
        rep(j,0,dd.size()){
            // print(dd[j]);
            sum[i+1][idx[dd[j]]]++;
        }
    }
    rep(j,0,310){
        rep(i,0,N+1){
            sum[i+1][j] += sum[i][j];
        }
    }
    rep(i,0,N){
        if(A[i] == 0) is_zero[i+1]++;
    }
    rep(i,0,N) is_zero[i+1] += is_zero[i];
    
    rep(q,0,Q){
        if(P[q] == 1){
            print("Yes");
            continue;
        }
        ll tt = is_zero[R[q]+1] - is_zero[L[q]];
        if(tt > 0){
            print("Yes");
            continue;
        }
        bool ok = true;
        bool is_big = false;
        ll v = P[q];
        rep(i,0,prime.size()){
            ll cnt = sum[R[q]+1][i] - sum[L[q]][i];
            ll idx = 0;
            while(idx < cnt){
                if(v % prime[i] != 0) break;
                v /= prime[i];
                idx++;
            }
        }
        if(v != 1){
            ok = false;
        }
        if(ok){
            print("Yes");
        }else{
            print("NO");
        }

    }



    
}
0