結果

問題 No.854 公平なりんご分配
ユーザー yuji9511yuji9511
提出日時 2019-07-26 23:07:24
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 3,904 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 161,648 KB
実行使用メモリ 132,720 KB
最終ジャッジ日時 2023-09-15 04:01:50
合計ジャッジ時間 14,708 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,100 KB
testcase_01 AC 2 ms
4,388 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
5,576 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
5,392 KB
testcase_08 AC 2 ms
5,484 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
5,440 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
5,628 KB
testcase_19 AC 2 ms
5,780 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 5 ms
5,772 KB
testcase_23 AC 4 ms
4,384 KB
testcase_24 AC 7 ms
6,564 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 8 ms
4,924 KB
testcase_27 AC 6 ms
6,956 KB
testcase_28 AC 5 ms
4,376 KB
testcase_29 AC 3 ms
5,928 KB
testcase_30 AC 4 ms
5,976 KB
testcase_31 AC 7 ms
4,476 KB
testcase_32 AC 72 ms
29,680 KB
testcase_33 AC 88 ms
19,464 KB
testcase_34 AC 164 ms
40,336 KB
testcase_35 AC 112 ms
31,924 KB
testcase_36 AC 71 ms
7,020 KB
testcase_37 AC 71 ms
29,960 KB
testcase_38 AC 51 ms
25,516 KB
testcase_39 AC 257 ms
42,652 KB
testcase_40 AC 105 ms
17,496 KB
testcase_41 AC 112 ms
27,776 KB
testcase_42 AC 140 ms
40,268 KB
testcase_43 AC 181 ms
29,704 KB
testcase_44 AC 189 ms
38,404 KB
testcase_45 AC 187 ms
11,756 KB
testcase_46 AC 249 ms
36,788 KB
testcase_47 AC 83 ms
21,628 KB
testcase_48 AC 129 ms
40,164 KB
testcase_49 AC 121 ms
40,292 KB
testcase_50 AC 63 ms
29,632 KB
testcase_51 AC 248 ms
38,596 KB
testcase_52 AC 151 ms
19,924 KB
testcase_53 AC 74 ms
19,452 KB
testcase_54 AC 150 ms
23,568 KB
testcase_55 AC 47 ms
19,396 KB
testcase_56 AC 42 ms
19,572 KB
testcase_57 AC 79 ms
17,576 KB
testcase_58 AC 159 ms
11,304 KB
testcase_59 AC 38 ms
17,144 KB
testcase_60 AC 102 ms
17,492 KB
testcase_61 AC 47 ms
7,068 KB
testcase_62 AC 124 ms
15,744 KB
testcase_63 AC 84 ms
15,552 KB
testcase_64 AC 31 ms
9,028 KB
testcase_65 AC 91 ms
37,884 KB
testcase_66 AC 72 ms
13,364 KB
testcase_67 AC 114 ms
23,924 KB
testcase_68 AC 119 ms
13,976 KB
testcase_69 AC 85 ms
42,112 KB
testcase_70 AC 41 ms
19,260 KB
testcase_71 AC 48 ms
17,364 KB
testcase_72 AC 97 ms
7,276 KB
testcase_73 AC 71 ms
29,772 KB
testcase_74 AC 150 ms
34,356 KB
testcase_75 AC 78 ms
17,680 KB
testcase_76 AC 113 ms
29,560 KB
testcase_77 AC 127 ms
40,132 KB
testcase_78 AC 165 ms
13,924 KB
testcase_79 AC 145 ms
26,196 KB
testcase_80 AC 137 ms
26,012 KB
testcase_81 AC 97 ms
27,792 KB
testcase_82 TLE -
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;
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];
    // print(sum[3][0] - sum[0][0]);
    // print(sum[N][0]);
    // print(idx[2]);
    // print(idx[3]);
    
    rep(q,0,Q){
        vector<ll> p = it.factor(P[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;
        }
        map<ll, ll> mp;
        rep(i,0,p.size()){
            mp[p[i]]++;
        }
        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;
        }
        // rep(i,0,prime.size()){
        //     ll cnt = sum[R[q]+1][i] - sum[L[q]][i];
        //     ll cnt2 = 0;
        //     ll tmp = P[q];
        //     while(tmp % prime[i] == 0){
        //         cnt2++;
        //         tmp /= prime[i];
        //     }
        //     if(cnt2 == 0) continue;
        //      if(cnt2 > cnt){
        //         ok = false;
        //     }
        // }
        if(ok){
            print("Yes");
        }else{
            print("NO");
        }

    }



    
}
0