結果

問題 No.854 公平なりんご分配
ユーザー chocopuuchocopuu
提出日時 2019-07-27 10:20:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 636 ms / 3,153 ms
コード長 1,715 bytes
コンパイル時間 2,901 ms
コンパイル使用メモリ 176,632 KB
実行使用メモリ 127,928 KB
最終ジャッジ日時 2023-09-15 05:57:50
合計ジャッジ時間 16,590 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 6 ms
4,812 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 6 ms
4,848 KB
testcase_27 AC 5 ms
4,900 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 6 ms
4,392 KB
testcase_32 AC 65 ms
29,236 KB
testcase_33 AC 70 ms
17,204 KB
testcase_34 AC 129 ms
39,216 KB
testcase_35 AC 90 ms
31,832 KB
testcase_36 AC 56 ms
5,192 KB
testcase_37 AC 63 ms
27,544 KB
testcase_38 AC 48 ms
22,900 KB
testcase_39 AC 190 ms
41,592 KB
testcase_40 AC 78 ms
15,552 KB
testcase_41 AC 88 ms
26,024 KB
testcase_42 AC 114 ms
38,636 KB
testcase_43 AC 132 ms
27,136 KB
testcase_44 AC 140 ms
35,996 KB
testcase_45 AC 132 ms
9,820 KB
testcase_46 AC 181 ms
35,788 KB
testcase_47 AC 69 ms
21,032 KB
testcase_48 AC 105 ms
37,984 KB
testcase_49 AC 100 ms
38,608 KB
testcase_50 AC 57 ms
27,308 KB
testcase_51 AC 179 ms
37,368 KB
testcase_52 AC 120 ms
18,240 KB
testcase_53 AC 67 ms
17,916 KB
testcase_54 AC 120 ms
20,928 KB
testcase_55 AC 46 ms
17,736 KB
testcase_56 AC 42 ms
18,404 KB
testcase_57 AC 63 ms
15,908 KB
testcase_58 AC 116 ms
8,736 KB
testcase_59 AC 36 ms
14,112 KB
testcase_60 AC 82 ms
15,684 KB
testcase_61 AC 40 ms
5,884 KB
testcase_62 AC 95 ms
13,956 KB
testcase_63 AC 82 ms
14,460 KB
testcase_64 AC 28 ms
7,624 KB
testcase_65 AC 81 ms
34,416 KB
testcase_66 AC 58 ms
11,192 KB
testcase_67 AC 99 ms
23,216 KB
testcase_68 AC 97 ms
11,956 KB
testcase_69 AC 81 ms
41,408 KB
testcase_70 AC 39 ms
15,340 KB
testcase_71 AC 46 ms
16,548 KB
testcase_72 AC 76 ms
5,376 KB
testcase_73 AC 66 ms
27,848 KB
testcase_74 AC 128 ms
33,892 KB
testcase_75 AC 66 ms
16,568 KB
testcase_76 AC 102 ms
27,096 KB
testcase_77 AC 112 ms
38,172 KB
testcase_78 AC 123 ms
12,920 KB
testcase_79 AC 121 ms
23,896 KB
testcase_80 AC 111 ms
24,992 KB
testcase_81 AC 86 ms
25,780 KB
testcase_82 AC 453 ms
127,900 KB
testcase_83 AC 590 ms
127,928 KB
testcase_84 AC 583 ms
127,748 KB
testcase_85 AC 628 ms
127,632 KB
testcase_86 AC 333 ms
127,648 KB
testcase_87 AC 444 ms
127,740 KB
testcase_88 AC 445 ms
127,672 KB
testcase_89 AC 445 ms
127,544 KB
testcase_90 AC 446 ms
127,632 KB
testcase_91 AC 443 ms
127,712 KB
testcase_92 AC 628 ms
127,668 KB
testcase_93 AC 636 ms
127,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

vector<int> P;
void make_primes(int n)
{
	vector<bool> primes;
	n++;
	primes.resize(n, true);
	primes[0] = primes[1] = false;
	FOR(i, 2, sqrt(n)) if (primes[i]) for (int j = 0; i * (j + 2) < n; j++)
		primes[i * (j + 2)] = false;

	FOR(i, 2, n) if (primes[i]) P.push_back(i);
}

signed main(){
	int N;
	cin >> N;
	make_primes(2000);
	vector<int> a(N); for(auto& e:a)cin >> e;
	vector<vector<int>>cnt(N+1,vector<int>(P.size(),0));
	vector<int>zero(N+1,0);
	REP(i,N){
		if(a[i] == 0)zero[i+1]++;
		REP(j,P.size()){
			while(a[i] != 0 && a[i]%P[j] == 0){
				a[i] /= P[j];
				cnt[i+1][j]++;
			}
		}
	}
	REP(i,N)zero[i+1] += zero[i];
	REP(i,N)REP(j,P.size())cnt[i+1][j] += cnt[i][j];
	int Q;
	cin >> Q;
	vector<int>l(Q),r(Q);
	vector<int>ans(Q);
	REP(i,Q){
		int p;
		cin >> p >> l[i] >> r[i];
		l[i]--;r[i]--;
		if(zero[r[i]+1]-zero[l[i]]){
			ans[i] = 0;continue;
		}
		vector<int>tmp(P.size(),0);
		REP(j,P.size()){
			while(p%P[j] == 0){
				p /= P[j];
				tmp[j]++;
			}
		}
		if(p > 1){
			ans[i] = 1;
			continue;
		}
		int flg = 0;
		REP(j,P.size()){
			if(tmp[j]>cnt[r[i]+1][j]-cnt[l[i]][j]){
				flg = 1;
				break;
			}
		}
		ans[i]=flg;
	}
	for(auto e:ans){
		if(e)cout<<"NO"<<endl;
		else cout<<"Yes"<<endl;
	}
}

0