結果
問題 | No.854 公平なりんご分配 |
ユーザー | yuji9511 |
提出日時 | 2019-07-26 23:08:38 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 724 ms / 3,153 ms |
コード長 | 3,271 bytes |
コンパイル時間 | 1,359 ms |
コンパイル使用メモリ | 175,080 KB |
実行使用メモリ | 128,464 KB |
最終ジャッジ日時 | 2024-07-02 09:15:48 |
合計ジャッジ時間 | 14,454 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,812 KB |
testcase_01 | AC | 4 ms
6,944 KB |
testcase_02 | AC | 5 ms
6,944 KB |
testcase_03 | AC | 3 ms
6,944 KB |
testcase_04 | AC | 4 ms
6,944 KB |
testcase_05 | AC | 4 ms
6,940 KB |
testcase_06 | AC | 4 ms
6,944 KB |
testcase_07 | AC | 4 ms
6,940 KB |
testcase_08 | AC | 4 ms
6,940 KB |
testcase_09 | AC | 5 ms
8,488 KB |
testcase_10 | AC | 4 ms
6,940 KB |
testcase_11 | AC | 4 ms
6,944 KB |
testcase_12 | AC | 4 ms
8,624 KB |
testcase_13 | AC | 4 ms
6,944 KB |
testcase_14 | AC | 4 ms
8,616 KB |
testcase_15 | AC | 4 ms
6,944 KB |
testcase_16 | AC | 4 ms
6,940 KB |
testcase_17 | AC | 4 ms
6,944 KB |
testcase_18 | AC | 3 ms
6,940 KB |
testcase_19 | AC | 3 ms
6,940 KB |
testcase_20 | AC | 3 ms
6,940 KB |
testcase_21 | AC | 4 ms
6,940 KB |
testcase_22 | AC | 6 ms
6,944 KB |
testcase_23 | AC | 5 ms
8,620 KB |
testcase_24 | AC | 8 ms
9,252 KB |
testcase_25 | AC | 5 ms
8,620 KB |
testcase_26 | AC | 8 ms
8,624 KB |
testcase_27 | AC | 7 ms
8,624 KB |
testcase_28 | AC | 6 ms
6,940 KB |
testcase_29 | AC | 4 ms
6,940 KB |
testcase_30 | AC | 6 ms
7,040 KB |
testcase_31 | AC | 8 ms
8,920 KB |
testcase_32 | AC | 60 ms
32,496 KB |
testcase_33 | AC | 71 ms
21,432 KB |
testcase_34 | AC | 135 ms
42,172 KB |
testcase_35 | AC | 92 ms
35,372 KB |
testcase_36 | AC | 59 ms
8,620 KB |
testcase_37 | AC | 57 ms
31,620 KB |
testcase_38 | AC | 44 ms
25,988 KB |
testcase_39 | AC | 211 ms
45,616 KB |
testcase_40 | AC | 87 ms
19,436 KB |
testcase_41 | AC | 94 ms
29,468 KB |
testcase_42 | AC | 120 ms
42,588 KB |
testcase_43 | AC | 148 ms
30,432 KB |
testcase_44 | AC | 152 ms
40,536 KB |
testcase_45 | AC | 148 ms
13,192 KB |
testcase_46 | AC | 201 ms
39,628 KB |
testcase_47 | AC | 66 ms
25,088 KB |
testcase_48 | AC | 106 ms
41,520 KB |
testcase_49 | AC | 100 ms
41,748 KB |
testcase_50 | AC | 53 ms
31,736 KB |
testcase_51 | AC | 200 ms
41,556 KB |
testcase_52 | AC | 115 ms
21,480 KB |
testcase_53 | AC | 57 ms
21,844 KB |
testcase_54 | AC | 112 ms
25,004 KB |
testcase_55 | AC | 36 ms
20,952 KB |
testcase_56 | AC | 34 ms
22,096 KB |
testcase_57 | AC | 60 ms
19,352 KB |
testcase_58 | AC | 124 ms
12,716 KB |
testcase_59 | AC | 29 ms
18,860 KB |
testcase_60 | AC | 80 ms
20,908 KB |
testcase_61 | AC | 36 ms
9,268 KB |
testcase_62 | AC | 97 ms
16,988 KB |
testcase_63 | AC | 57 ms
17,616 KB |
testcase_64 | AC | 26 ms
11,468 KB |
testcase_65 | AC | 77 ms
38,500 KB |
testcase_66 | AC | 52 ms
15,640 KB |
testcase_67 | AC | 86 ms
27,292 KB |
testcase_68 | AC | 86 ms
14,920 KB |
testcase_69 | AC | 73 ms
44,432 KB |
testcase_70 | AC | 28 ms
18,864 KB |
testcase_71 | AC | 36 ms
20,908 KB |
testcase_72 | AC | 74 ms
9,376 KB |
testcase_73 | AC | 56 ms
32,408 KB |
testcase_74 | AC | 120 ms
38,056 KB |
testcase_75 | AC | 61 ms
20,908 KB |
testcase_76 | AC | 92 ms
31,276 KB |
testcase_77 | AC | 100 ms
41,520 KB |
testcase_78 | AC | 128 ms
16,824 KB |
testcase_79 | AC | 107 ms
27,264 KB |
testcase_80 | AC | 103 ms
29,228 KB |
testcase_81 | AC | 69 ms
29,228 KB |
testcase_82 | AC | 361 ms
128,432 KB |
testcase_83 | AC | 695 ms
128,428 KB |
testcase_84 | AC | 688 ms
128,400 KB |
testcase_85 | AC | 454 ms
128,244 KB |
testcase_86 | AC | 446 ms
128,384 KB |
testcase_87 | AC | 349 ms
128,348 KB |
testcase_88 | AC | 345 ms
128,428 KB |
testcase_89 | AC | 342 ms
128,424 KB |
testcase_90 | AC | 369 ms
128,464 KB |
testcase_91 | AC | 344 ms
128,300 KB |
testcase_92 | AC | 712 ms
128,304 KB |
testcase_93 | AC | 724 ms
128,400 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> lpair; const ll MOD = 1e9 + 7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define print2(x,y) cout << (x) << " " << (y) << endl; #define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];}; int sum[100010][310] = {}; ll is_zero[100010] = {}; struct Integer{ public: Integer(ll n){ } ll gcd(ll a,ll b){return b ? gcd(b, a % b) : a;} //最大公約数 ll lcm(ll a,ll b){return a / gcd(a, b) * b;} //最小公倍数 bool isPrime(ll x){ if(x < 2) return false; if(x == 2) return true; if(x % 2 == 0) return false; for(ll i = 3;i <= sqrt(x) + 1;i += 2) if(x % i == 0) return false; return true; } vector<ll> divisor(ll M){ //約数の全列挙 vector<ll> dd; for(ll i = 1; i * i <= M; i++){ if(M % i == 0){ dd.push_back(i); if(i * i != M){ dd.push_back(M / i); } } } sort(dd.begin(), dd.end()); return dd; } vector<ll> factor(ll M){ //素因数分解 vector<ll> dd; if(M == 1){ dd.push_back(1); return dd; } for(ll i = 2; i*i <= M; i++){ while(M % i == 0){ dd.push_back(i); M /= i; } } if(M != 1) dd.push_back(M); sort(dd.begin(), dd.end()); return dd; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; ll A[100010]; rep(i,0,N) cin >> A[i]; ll Q; cin >> Q; ll P[100010], L[100010], R[100010]; rep(i,0,Q){ cin >> P[i] >> L[i] >> R[i]; L[i]--; R[i]--; } Integer it(0); vector<ll> prime; // prime.push_back(1); rep(i,2,2001){ if(it.isPrime(i)) prime.push_back(i); } map<ll, ll> idx; rep(i,0,prime.size()){ idx[prime[i]] = i; } rep(i,0,N){ if(A[i] == 1 || A[i] == 0) continue; vector<ll> dd = it.factor(A[i]); rep(j,0,dd.size()){ // print(dd[j]); sum[i+1][idx[dd[j]]]++; } } rep(j,0,310){ rep(i,0,N+1){ sum[i+1][j] += sum[i][j]; } } rep(i,0,N){ if(A[i] == 0) is_zero[i+1]++; } rep(i,0,N) is_zero[i+1] += is_zero[i]; rep(q,0,Q){ if(P[q] == 1){ print("Yes"); continue; } ll tt = is_zero[R[q]+1] - is_zero[L[q]]; if(tt > 0){ print("Yes"); continue; } bool ok = true; bool is_big = false; ll v = P[q]; rep(i,0,prime.size()){ ll cnt = sum[R[q]+1][i] - sum[L[q]][i]; ll idx = 0; while(idx < cnt){ if(v % prime[i] != 0) break; v /= prime[i]; idx++; } } if(v != 1){ ok = false; } if(ok){ print("Yes"); }else{ print("NO"); } } }