結果

問題 No.854 公平なりんご分配
ユーザー chocoruskchocorusk
提出日時 2019-07-26 22:05:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,374 ms / 3,153 ms
コード長 1,993 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 100,672 KB
実行使用メモリ 125,400 KB
最終ジャッジ日時 2023-09-15 01:32:47
合計ジャッジ時間 23,932 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
124,796 KB
testcase_01 AC 35 ms
125,124 KB
testcase_02 AC 34 ms
124,796 KB
testcase_03 AC 33 ms
124,988 KB
testcase_04 AC 35 ms
124,800 KB
testcase_05 AC 34 ms
125,060 KB
testcase_06 AC 35 ms
124,884 KB
testcase_07 AC 34 ms
124,860 KB
testcase_08 AC 34 ms
124,876 KB
testcase_09 AC 34 ms
124,912 KB
testcase_10 AC 33 ms
125,304 KB
testcase_11 AC 35 ms
124,896 KB
testcase_12 AC 35 ms
124,900 KB
testcase_13 AC 35 ms
124,876 KB
testcase_14 AC 34 ms
124,916 KB
testcase_15 AC 35 ms
124,992 KB
testcase_16 AC 35 ms
124,916 KB
testcase_17 AC 34 ms
124,832 KB
testcase_18 AC 35 ms
124,992 KB
testcase_19 AC 36 ms
125,128 KB
testcase_20 AC 36 ms
124,856 KB
testcase_21 AC 35 ms
124,880 KB
testcase_22 AC 39 ms
124,800 KB
testcase_23 AC 38 ms
125,112 KB
testcase_24 AC 42 ms
124,884 KB
testcase_25 AC 37 ms
124,872 KB
testcase_26 AC 45 ms
125,024 KB
testcase_27 AC 39 ms
124,808 KB
testcase_28 AC 38 ms
125,088 KB
testcase_29 AC 35 ms
124,792 KB
testcase_30 AC 36 ms
125,008 KB
testcase_31 AC 40 ms
125,240 KB
testcase_32 AC 114 ms
124,980 KB
testcase_33 AC 160 ms
125,200 KB
testcase_34 AC 250 ms
124,960 KB
testcase_35 AC 176 ms
124,884 KB
testcase_36 AC 134 ms
124,924 KB
testcase_37 AC 116 ms
125,212 KB
testcase_38 AC 91 ms
124,952 KB
testcase_39 AC 415 ms
125,200 KB
testcase_40 AC 191 ms
124,868 KB
testcase_41 AC 186 ms
124,920 KB
testcase_42 AC 211 ms
124,944 KB
testcase_43 AC 301 ms
124,984 KB
testcase_44 AC 297 ms
124,996 KB
testcase_45 AC 303 ms
125,032 KB
testcase_46 AC 405 ms
124,984 KB
testcase_47 AC 152 ms
125,132 KB
testcase_48 AC 197 ms
125,216 KB
testcase_49 AC 174 ms
125,196 KB
testcase_50 AC 99 ms
124,960 KB
testcase_51 AC 404 ms
125,120 KB
testcase_52 AC 247 ms
125,036 KB
testcase_53 AC 123 ms
125,168 KB
testcase_54 AC 240 ms
125,220 KB
testcase_55 AC 87 ms
125,036 KB
testcase_56 AC 84 ms
124,896 KB
testcase_57 AC 137 ms
124,920 KB
testcase_58 AC 252 ms
125,028 KB
testcase_59 AC 77 ms
125,180 KB
testcase_60 AC 179 ms
125,152 KB
testcase_61 AC 96 ms
125,308 KB
testcase_62 AC 205 ms
124,908 KB
testcase_63 AC 135 ms
125,192 KB
testcase_64 AC 74 ms
125,180 KB
testcase_65 AC 129 ms
124,892 KB
testcase_66 AC 125 ms
125,116 KB
testcase_67 AC 179 ms
125,180 KB
testcase_68 AC 190 ms
125,136 KB
testcase_69 AC 110 ms
124,936 KB
testcase_70 AC 80 ms
124,912 KB
testcase_71 AC 89 ms
124,852 KB
testcase_72 AC 162 ms
124,908 KB
testcase_73 AC 103 ms
124,988 KB
testcase_74 AC 211 ms
125,060 KB
testcase_75 AC 135 ms
124,832 KB
testcase_76 AC 158 ms
124,912 KB
testcase_77 AC 166 ms
124,996 KB
testcase_78 AC 264 ms
125,180 KB
testcase_79 AC 218 ms
124,900 KB
testcase_80 AC 208 ms
124,904 KB
testcase_81 AC 137 ms
124,980 KB
testcase_82 AC 463 ms
125,400 KB
testcase_83 AC 864 ms
125,276 KB
testcase_84 AC 858 ms
125,352 KB
testcase_85 AC 905 ms
125,380 KB
testcase_86 AC 306 ms
125,192 KB
testcase_87 AC 463 ms
125,188 KB
testcase_88 AC 472 ms
125,316 KB
testcase_89 AC 461 ms
125,188 KB
testcase_90 AC 476 ms
125,180 KB
testcase_91 AC 467 ms
125,320 KB
testcase_92 AC 1,374 ms
125,320 KB
testcase_93 AC 1,367 ms
125,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MAX=2000;
vector<ll> prime;
bool isprime[MAX];
void sieve(){
	for(ll i=3; i<MAX; i+=2){
		isprime[i]=1;
	}
	isprime[2]=1;
	prime.push_back(2);
	for(ll i=3; i<MAX; i++){
		if(isprime[i]){
			prime.push_back(i);
			for(ll j=2*i; j<MAX; j+=i){
				isprime[j]=0;
			}
		}
	}
	return;
}
int main()
{
    int n, q; cin>>n;
    sieve();
    int z[100010]={};
    int a[100010];
    int cnt[310][100010]={};
    for(int i=1; i<=n; i++){
        cin>>a[i];
        if(a[i]==0){
            z[i]++;
            continue;
        }
        for(int j=0; j<prime.size(); j++){
            int p=prime[j];
            while(a[i]%p==0){
                cnt[j][i]++;
                a[i]/=p;
            }
        }
    }
    for(int i=1; i<=n; i++){
        z[i]+=z[i-1];
        for(int j=0; j<prime.size(); j++) cnt[j][i]+=cnt[j][i-1];
    }
    cin>>q;
    for(int i=0; i<q; i++){
        int p, l, r;
        cin>>p>>l>>r;
        if(z[r]-z[l-1]>0 || p==1){
            cout<<"Yes"<<endl;
            continue;
        }
        int cp[310]={};
        for(int j=0; j<prime.size(); j++){
            while(p%prime[j]==0){
                cp[j]++;
                p/=prime[j];
            }
        }
        if(p>1){
            cout<<"NO"<<endl;
            continue;
        }
        bool dame=0;
        for(int j=0; j<prime.size(); j++){
            if(cp[j]>cnt[j][r]-cnt[j][l-1]){
                dame=1;
                break;
            }
        }
        if(dame) cout<<"NO"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}
0