結果

問題 No.854 公平なりんご分配
ユーザー totori_nyaatotori_nyaa
提出日時 2019-08-24 17:07:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 418 ms / 3,153 ms
コード長 1,754 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 171,660 KB
実行使用メモリ 139,904 KB
最終ジャッジ日時 2024-04-22 13:27:27
合計ジャッジ時間 11,099 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 6 ms
5,376 KB
testcase_27 AC 5 ms
5,376 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 5 ms
5,376 KB
testcase_32 AC 40 ms
32,128 KB
testcase_33 AC 48 ms
18,880 KB
testcase_34 AC 85 ms
43,264 KB
testcase_35 AC 58 ms
34,560 KB
testcase_36 AC 30 ms
5,376 KB
testcase_37 AC 41 ms
30,336 KB
testcase_38 AC 32 ms
25,400 KB
testcase_39 AC 114 ms
45,568 KB
testcase_40 AC 49 ms
16,420 KB
testcase_41 AC 57 ms
28,288 KB
testcase_42 AC 73 ms
42,496 KB
testcase_43 AC 80 ms
29,440 KB
testcase_44 AC 86 ms
39,552 KB
testcase_45 AC 78 ms
10,496 KB
testcase_46 AC 110 ms
38,912 KB
testcase_47 AC 44 ms
22,924 KB
testcase_48 AC 68 ms
41,728 KB
testcase_49 AC 65 ms
42,624 KB
testcase_50 AC 39 ms
30,080 KB
testcase_51 AC 108 ms
40,832 KB
testcase_52 AC 60 ms
19,732 KB
testcase_53 AC 35 ms
19,328 KB
testcase_54 AC 62 ms
22,656 KB
testcase_55 AC 27 ms
19,544 KB
testcase_56 AC 26 ms
20,356 KB
testcase_57 AC 37 ms
17,092 KB
testcase_58 AC 64 ms
9,088 KB
testcase_59 AC 21 ms
15,356 KB
testcase_60 AC 45 ms
16,980 KB
testcase_61 AC 18 ms
6,016 KB
testcase_62 AC 51 ms
14,812 KB
testcase_63 AC 32 ms
15,488 KB
testcase_64 AC 15 ms
8,192 KB
testcase_65 AC 52 ms
37,632 KB
testcase_66 AC 31 ms
11,904 KB
testcase_67 AC 51 ms
25,216 KB
testcase_68 AC 44 ms
12,672 KB
testcase_69 AC 55 ms
45,696 KB
testcase_70 AC 22 ms
16,592 KB
testcase_71 AC 25 ms
17,960 KB
testcase_72 AC 38 ms
5,504 KB
testcase_73 AC 40 ms
30,720 KB
testcase_74 AC 68 ms
36,864 KB
testcase_75 AC 36 ms
18,064 KB
testcase_76 AC 49 ms
29,440 KB
testcase_77 AC 62 ms
41,728 KB
testcase_78 AC 66 ms
13,824 KB
testcase_79 AC 62 ms
25,856 KB
testcase_80 AC 60 ms
27,136 KB
testcase_81 AC 45 ms
28,288 KB
testcase_82 AC 186 ms
139,872 KB
testcase_83 AC 321 ms
139,776 KB
testcase_84 AC 350 ms
139,772 KB
testcase_85 AC 265 ms
139,264 KB
testcase_86 AC 177 ms
136,188 KB
testcase_87 AC 218 ms
139,676 KB
testcase_88 AC 209 ms
139,904 KB
testcase_89 AC 212 ms
139,824 KB
testcase_90 AC 206 ms
139,776 KB
testcase_91 AC 220 ms
139,824 KB
testcase_92 AC 418 ms
139,776 KB
testcase_93 AC 382 ms
139,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


vector<int> prime;

vector<pair<int,int>> factorize(int p){
    vector<pair<int,int>> ret;
    for(auto i:prime){
        if(i>p) break;
        int cnt=0;
        while(p%i==0){
            p/=i;
            cnt++;
        }
        if(cnt){
            ret.push_back(make_pair(i,cnt));
        }
    }
    return ret;
} 

int sum[100010][333];

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    vector<vector<pair<int,int>>> a(n+1);
    bool check[2222]={};

    int pnum[2222]={};
    int cnt=0;
    
    for(int i=2;i<=2000;i++){
        if(check[i]==0){
            for(int j=i+i;j<=2000;j+=i){
                check[j]=1;
            }
            prime.push_back(i);
            pnum[i] = cnt;
            cnt++; 
        }
    }

    int zero[n+1]={};
    for(int i=1;i<=n;i++){
        int t;
        cin>>t;
        if(t==0){
            zero[i]++;
        }
        zero[i] += zero[i-1];
        a[i] = factorize(t);
        for(auto j:a[i]){
            sum[i][pnum[j.first]]+=j.second;
        }
        for(int j=0;j<333;j++){
            sum[i][j] += sum[i-1][j];
        }
    }

    
    


    int q;
    cin>>q;
    while(q--){
        int p,l,r;
        cin>>p>>l>>r;
        l--;
        if(zero[r]-zero[l]){
            cout<<"Yes\n";
            continue;
        }
        int c[333];
        for(int i=0;i<prime.size();i++){
            c[i] = sum[r][i] - sum[l][i];
            while(c[i] && p%prime[i]==0){
                p/=prime[i];
                c[i]--;
            }
        }
        if(p==1){
            cout<<"Yes\n";
        }
        else cout<<"NO\n";

    }

    
}
0