結果

問題 No.854 公平なりんご分配
ユーザー yuji9511yuji9511
提出日時 2019-07-26 22:57:51
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 3,559 bytes
コンパイル時間 3,172 ms
コンパイル使用メモリ 161,728 KB
実行使用メモリ 44,028 KB
最終ジャッジ日時 2023-09-15 03:40:54
合計ジャッジ時間 13,958 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,152 KB
testcase_01 AC 3 ms
5,548 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
5,536 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 3 ms
5,492 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
5,484 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
5,608 KB
testcase_18 AC 3 ms
5,716 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 4 ms
6,256 KB
testcase_24 AC 5 ms
4,788 KB
testcase_25 AC 4 ms
6,132 KB
testcase_26 AC 6 ms
6,692 KB
testcase_27 AC 5 ms
4,612 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 3 ms
5,852 KB
testcase_30 AC 4 ms
5,928 KB
testcase_31 AC 6 ms
4,512 KB
testcase_32 AC 62 ms
29,560 KB
testcase_33 AC 54 ms
19,552 KB
testcase_34 AC 113 ms
42,168 KB
testcase_35 AC 81 ms
31,884 KB
testcase_36 AC 44 ms
7,376 KB
testcase_37 AC 59 ms
29,604 KB
testcase_38 AC 45 ms
23,708 KB
testcase_39 AC 158 ms
44,028 KB
testcase_40 AC 60 ms
17,492 KB
testcase_41 AC 76 ms
27,916 KB
testcase_42 AC 103 ms
41,932 KB
testcase_43 AC 108 ms
29,484 KB
testcase_44 AC 121 ms
38,340 KB
testcase_45 AC 95 ms
12,992 KB
testcase_46 AC 146 ms
36,452 KB
testcase_47 AC 56 ms
21,444 KB
testcase_48 AC 98 ms
40,172 KB
testcase_49 AC 94 ms
42,096 KB
testcase_50 AC 56 ms
29,684 KB
testcase_51 AC 147 ms
38,548 KB
testcase_52 AC 103 ms
21,384 KB
testcase_53 AC 61 ms
19,548 KB
testcase_54 AC 104 ms
22,080 KB
testcase_55 AC 42 ms
21,196 KB
testcase_56 AC 37 ms
21,300 KB
testcase_57 AC 54 ms
17,492 KB
testcase_58 AC 90 ms
11,172 KB
testcase_59 AC 31 ms
15,116 KB
testcase_60 AC 71 ms
17,596 KB
testcase_61 AC 35 ms
8,824 KB
testcase_62 AC 79 ms
15,724 KB
testcase_63 AC 71 ms
15,620 KB
testcase_64 AC 24 ms
10,820 KB
testcase_65 AC 83 ms
37,764 KB
testcase_66 AC 50 ms
14,916 KB
testcase_67 AC 90 ms
25,680 KB
testcase_68 AC 93 ms
13,676 KB
testcase_69 AC 83 ms
42,128 KB
testcase_70 AC 38 ms
19,188 KB
testcase_71 AC 44 ms
17,404 KB
testcase_72 AC 60 ms
9,080 KB
testcase_73 AC 67 ms
31,768 KB
testcase_74 AC 122 ms
34,204 KB
testcase_75 AC 56 ms
19,456 KB
testcase_76 AC 102 ms
28,124 KB
testcase_77 AC 113 ms
38,252 KB
testcase_78 AC 100 ms
13,884 KB
testcase_79 AC 109 ms
26,268 KB
testcase_80 AC 103 ms
26,008 KB
testcase_81 AC 86 ms
29,600 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;
        for(auto &e: mp){
            ll sosuu = e.first;
            ll num = e.second;
            if(sosuu > 2000){
                is_big = true;
                break;
            }
            ll idx2 = idx[sosuu];
            if(sum[R[q]+1][idx2] - sum[L[q]][idx2] < num){
                ok = false;
            }
        }
        if(is_big){
            print("NO");
        
        }else if(ok){
            print("Yes");
        }else{
            print("NO");
        }

    }



    
}
0