結果

問題 No.854 公平なりんご分配
ユーザー leaf_1415leaf_1415
提出日時 2019-07-26 22:38:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 700 ms / 3,153 ms
コード長 1,738 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 79,820 KB
実行使用メモリ 246,432 KB
最終ジャッジ日時 2023-09-15 02:35:38
合計ジャッジ時間 15,578 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
7,304 KB
testcase_01 AC 11 ms
5,324 KB
testcase_02 AC 11 ms
7,164 KB
testcase_03 AC 11 ms
7,388 KB
testcase_04 AC 10 ms
7,484 KB
testcase_05 AC 11 ms
7,260 KB
testcase_06 AC 11 ms
7,384 KB
testcase_07 AC 11 ms
7,144 KB
testcase_08 AC 11 ms
7,152 KB
testcase_09 AC 11 ms
7,436 KB
testcase_10 AC 11 ms
7,380 KB
testcase_11 AC 10 ms
7,212 KB
testcase_12 AC 13 ms
17,796 KB
testcase_13 AC 13 ms
17,560 KB
testcase_14 AC 11 ms
7,156 KB
testcase_15 AC 13 ms
13,364 KB
testcase_16 AC 13 ms
17,488 KB
testcase_17 AC 13 ms
17,472 KB
testcase_18 AC 13 ms
17,520 KB
testcase_19 AC 13 ms
17,404 KB
testcase_20 AC 12 ms
15,436 KB
testcase_21 AC 13 ms
15,428 KB
testcase_22 AC 35 ms
97,556 KB
testcase_23 AC 34 ms
110,356 KB
testcase_24 AC 39 ms
125,152 KB
testcase_25 AC 32 ms
108,132 KB
testcase_26 AC 38 ms
118,848 KB
testcase_27 AC 36 ms
116,960 KB
testcase_28 AC 28 ms
79,160 KB
testcase_29 AC 29 ms
89,380 KB
testcase_30 AC 33 ms
110,016 KB
testcase_31 AC 38 ms
122,788 KB
testcase_32 AC 90 ms
169,560 KB
testcase_33 AC 100 ms
150,028 KB
testcase_34 AC 145 ms
182,528 KB
testcase_35 AC 112 ms
172,708 KB
testcase_36 AC 94 ms
125,488 KB
testcase_37 AC 85 ms
168,684 KB
testcase_38 AC 74 ms
161,740 KB
testcase_39 AC 214 ms
186,808 KB
testcase_40 AC 109 ms
148,156 KB
testcase_41 AC 114 ms
165,448 KB
testcase_42 AC 130 ms
182,120 KB
testcase_43 AC 159 ms
167,960 KB
testcase_44 AC 159 ms
177,432 KB
testcase_45 AC 172 ms
135,812 KB
testcase_46 AC 202 ms
177,032 KB
testcase_47 AC 96 ms
156,768 KB
testcase_48 AC 121 ms
181,908 KB
testcase_49 AC 115 ms
182,256 KB
testcase_50 AC 81 ms
168,280 KB
testcase_51 AC 199 ms
179,740 KB
testcase_52 AC 153 ms
154,496 KB
testcase_53 AC 96 ms
152,400 KB
testcase_54 AC 149 ms
158,496 KB
testcase_55 AC 75 ms
152,440 KB
testcase_56 AC 70 ms
154,848 KB
testcase_57 AC 96 ms
150,560 KB
testcase_58 AC 160 ms
136,552 KB
testcase_59 AC 65 ms
145,740 KB
testcase_60 AC 114 ms
150,732 KB
testcase_61 AC 75 ms
130,092 KB
testcase_62 AC 128 ms
145,164 KB
testcase_63 AC 105 ms
147,716 KB
testcase_64 AC 60 ms
133,940 KB
testcase_65 AC 99 ms
178,436 KB
testcase_66 AC 90 ms
141,060 KB
testcase_67 AC 126 ms
163,700 KB
testcase_68 AC 131 ms
143,436 KB
testcase_69 AC 94 ms
188,884 KB
testcase_70 AC 70 ms
150,400 KB
testcase_71 AC 76 ms
151,320 KB
testcase_72 AC 117 ms
129,632 KB
testcase_73 AC 90 ms
170,924 KB
testcase_74 AC 147 ms
177,804 KB
testcase_75 AC 95 ms
151,396 KB
testcase_76 AC 128 ms
169,952 KB
testcase_77 AC 130 ms
183,696 KB
testcase_78 AC 156 ms
144,456 KB
testcase_79 AC 147 ms
164,100 KB
testcase_80 AC 139 ms
165,028 KB
testcase_81 AC 113 ms
167,496 KB
testcase_82 AC 356 ms
246,312 KB
testcase_83 AC 436 ms
244,172 KB
testcase_84 AC 700 ms
244,148 KB
testcase_85 AC 431 ms
127,436 KB
testcase_86 AC 296 ms
127,428 KB
testcase_87 AC 346 ms
246,180 KB
testcase_88 AC 346 ms
246,176 KB
testcase_89 AC 339 ms
246,332 KB
testcase_90 AC 349 ms
246,432 KB
testcase_91 AC 344 ms
246,204 KB
testcase_92 AC 528 ms
244,388 KB
testcase_93 AC 533 ms
244,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#define llint long long

using namespace std;

int n, Q;
int a[100005];
int d[325][100005];
int sum[325][100005];
unordered_map<int, int> mp, fmp[2005];

bool prime[2005];
vector<llint> pvec;

int main(void)
{
	for(int i = 2; i < 55; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 2005; j+=i) prime[j] = true;
	}
	for(int i = 2; i < 2005; i++){
		if(!prime[i]) pvec.push_back(i);
	}
	int m = pvec.size();
	
	for(int i = 1; i < 2005; i++){
		for(int j = 0; j < m; j++){
			int t = i;
			while(t % pvec[j] == 0){
				fmp[i][j]++;
				t /= pvec[j];
			}
		}
	}
	
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++){
		for(auto it = fmp[a[i]].begin(); it != fmp[a[i]].end(); it++) d[it->first][i] = it->second;
	}
	for(int i = 0; i < m; i++){
		for(int j = 1; j <= n; j++) sum[i][j] = sum[i][j-1] + d[i][j];
	}
	
	for(int i = 1; i <= n; i++){
		if(a[i] == 0) d[320][i] = 1;
	}
	for(int i = 1; i <= n; i++){
		sum[320][i] = sum[320][i-1] + d[320][i];
	}
	
	cin >> Q;
	int p, l, r;
	for(int q = 0; q < Q; q++){
		cin >> p >> l >> r;
		
		if(sum[320][r]-sum[320][l-1] > 0){
			printf("Yes\n");
			continue;
		}
		
		mp.clear();
		int t = p;
		for(int i = 0; i < m; i++){
			if(pvec[i] > t) break;
			while(t % pvec[i] == 0){
				mp[i]++;
				t /= pvec[i];
			}
		}
		if(t > 1){
			printf("NO\n");
			continue;
		}
		
		bool flag = true;
		for(auto it = mp.begin(); it != mp.end(); it++){
			if(it->second > sum[it->first][r]-sum[it->first][l-1]){
				flag = false;
				break;
			}
		}
		if(flag) printf("Yes\n");
		else printf("NO\n");
	}
	
	return 0;
}
0