結果

問題 No.854 公平なりんご分配
ユーザー snteasntea
提出日時 2019-07-26 23:20:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,608 ms / 3,153 ms
コード長 4,277 bytes
コンパイル時間 2,138 ms
コンパイル使用メモリ 185,592 KB
実行使用メモリ 122,684 KB
最終ジャッジ日時 2023-09-15 04:39:34
合計ジャッジ時間 20,779 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,388 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 5 ms
4,384 KB
testcase_23 AC 5 ms
4,384 KB
testcase_24 AC 7 ms
4,384 KB
testcase_25 AC 4 ms
4,384 KB
testcase_26 AC 8 ms
4,384 KB
testcase_27 AC 5 ms
4,384 KB
testcase_28 AC 5 ms
4,384 KB
testcase_29 AC 3 ms
4,384 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 7 ms
4,380 KB
testcase_32 AC 83 ms
28,348 KB
testcase_33 AC 128 ms
16,480 KB
testcase_34 AC 230 ms
37,816 KB
testcase_35 AC 150 ms
30,412 KB
testcase_36 AC 78 ms
4,576 KB
testcase_37 AC 83 ms
26,864 KB
testcase_38 AC 59 ms
22,288 KB
testcase_39 AC 404 ms
39,944 KB
testcase_40 AC 143 ms
14,604 KB
testcase_41 AC 158 ms
24,880 KB
testcase_42 AC 192 ms
37,292 KB
testcase_43 AC 286 ms
25,952 KB
testcase_44 AC 279 ms
34,676 KB
testcase_45 AC 206 ms
9,068 KB
testcase_46 AC 393 ms
34,172 KB
testcase_47 AC 117 ms
20,476 KB
testcase_48 AC 167 ms
36,560 KB
testcase_49 AC 150 ms
37,300 KB
testcase_50 AC 70 ms
26,532 KB
testcase_51 AC 388 ms
35,796 KB
testcase_52 AC 181 ms
17,308 KB
testcase_53 AC 75 ms
17,004 KB
testcase_54 AC 176 ms
19,928 KB
testcase_55 AC 46 ms
17,028 KB
testcase_56 AC 46 ms
17,768 KB
testcase_57 AC 93 ms
14,868 KB
testcase_58 AC 162 ms
7,804 KB
testcase_59 AC 37 ms
13,268 KB
testcase_60 AC 120 ms
14,948 KB
testcase_61 AC 42 ms
5,156 KB
testcase_62 AC 143 ms
13,216 KB
testcase_63 AC 72 ms
13,612 KB
testcase_64 AC 31 ms
7,276 KB
testcase_65 AC 96 ms
33,204 KB
testcase_66 AC 71 ms
10,504 KB
testcase_67 AC 121 ms
22,324 KB
testcase_68 AC 111 ms
11,168 KB
testcase_69 AC 78 ms
40,000 KB
testcase_70 AC 40 ms
14,596 KB
testcase_71 AC 47 ms
15,964 KB
testcase_72 AC 101 ms
4,836 KB
testcase_73 AC 63 ms
27,000 KB
testcase_74 AC 154 ms
32,356 KB
testcase_75 AC 91 ms
16,040 KB
testcase_76 AC 93 ms
26,004 KB
testcase_77 AC 111 ms
36,524 KB
testcase_78 AC 182 ms
11,960 KB
testcase_79 AC 164 ms
22,768 KB
testcase_80 AC 158 ms
24,076 KB
testcase_81 AC 87 ms
25,128 KB
testcase_82 AC 263 ms
122,612 KB
testcase_83 AC 752 ms
122,684 KB
testcase_84 AC 754 ms
122,640 KB
testcase_85 AC 471 ms
71,244 KB
testcase_86 AC 31 ms
4,384 KB
testcase_87 AC 262 ms
122,608 KB
testcase_88 AC 261 ms
122,588 KB
testcase_89 AC 262 ms
122,548 KB
testcase_90 AC 261 ms
122,612 KB
testcase_91 AC 261 ms
122,560 KB
testcase_92 AC 1,607 ms
122,560 KB
testcase_93 AC 1,608 ms
122,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

const array<int, 4> dx = {0, 1, 0, -1};
const array<int, 4> dy = {1, 0, -1, 0};


typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	cout.setf(ios::fixed);
	cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

std::vector<bool> eratosthenes(int n){
	std::vector<bool> res(n+1,true);
	res[0] = false;
	res[1] = false;
	for(long long i = 2; i*i <= n; i++){
		for(long long j = 2; i*j <= n; j++){
			res[i*j] = false;
		}
	}
	return res;
}

template<typename T>
unordered_map<T,int> primeFactorizem(T x){
	unordered_map<T,int> res;
	for(T i = 2; i*i <= x; i++){
		while(x%i == 0){
			res[i]++;
			x /= i;
		}
	}
	if(x != 1) res[x]++;
	return res;
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<int> a(n);
		REP(i, n) cin >> a[i];
		int ma = *max_element(ALL(a));
		if(ma == 1) {
			vector<int> zero_cnt(n+1);
			REP(i, n) {
				zero_cnt[i+1] = zero_cnt[i] + (a[i] == 0);
			}
			dpite(ALL(zero_cnt));
			int q;
			cin >> q;
			REP(_, q) {
				LL p;
				int l, r;
				cin >> p >> l >> r;
				l--;
				DEBUG(r); DEBUG(l);
				DEBUG(zero_cnt[r] - zero_cnt[l]);
				if(p >= 2) {
					cout << "NO" << endl;
				} else {
					if(zero_cnt[r] - zero_cnt[l] == 0) {
						cout << "Yes" << endl;
					} else {
						cout << "Yes" << endl;
					}
				}
			}
			continue;
		}
		auto era = eratosthenes(ma);
		vector<int> pv;
		REP(i, SZ(era)) if(era[i]) {
			DEBUG(i);
			pv.push_back(i);
		}
		vector<vector<int>> imos(SZ(pv), vector<int>(n + 1));
		vector<int> zero_cnt(n+1);
		REP(i, n) {
			// DEBUG(a[i]);
			int t = a[i];
			if(t == 0) {
				zero_cnt[i+1]++;
			} else {
				REP(j, SZ(pv)) {
					while(t % pv[j] == 0) {
						t /= pv[j];
						imos[j][i + 1]++;
					}
				}
				assert(t == 1);
			}
			// DEBUG(t);
		}

		REP(i, n) zero_cnt[i+1] += zero_cnt[i];

		REP(i, SZ(pv)) REP(j, n) {
			imos[i][j+1] += imos[i][j];
		}
		int q;
		cin >> q;
		REP(_, q) {
			// DEBUG(_);
			LL p;
			int l, r;
			cin >> p >> l >> r; l--;
			if(zero_cnt[r] - zero_cnt[l] != 0) {
				cout << "Yes" << endl;
				continue;
			}
			vector<int> pf(SZ(pv));
			bool ans = true;
			REP(i, SZ(pv)) {
				while(p % pv[i] == 0) {
					p /= pv[i];
					pf[i]++;
				}
			}
			REP(i, SZ(pv)) {
				if(pf[i] > imos[i][r] - imos[i][l]) {
					ans = false;
				}
			}
			if(p != 1) {
				ans = false;
			}

			if(ans) {
				cout << "Yes" << endl;
			} else {
				cout << "NO" << endl;
			}
		}
	}
}
0