結果
問題 |
No.854 公平なりんご分配
|
ユーザー |
![]() |
提出日時 | 2019-07-26 23:53:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,173 bytes |
コンパイル時間 | 1,985 ms |
コンパイル使用メモリ | 182,940 KB |
実行使用メモリ | 128,000 KB |
最終ジャッジ日時 | 2024-07-02 10:10:20 |
合計ジャッジ時間 | 14,674 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 55 WA * 37 |
ソースコード
#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); } vector<pair<long long, long long> > prime_factorize(long long n) { //計算量は√N!!! vector<pair<long long, long long> > res; for (long long p = 2; p * p <= n; ++p) { if (n % p != 0) continue; int num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back(make_pair(p, num)); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } signed main(){ int N; cin >> N; make_primes(2000); vector<int>inv(2000,0); REP(i,P.size())inv[P[i]] = i; 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]++; auto tmp = prime_factorize(a[i]); for(auto e:tmp){ cnt[i+1][inv[e.first]] += e.second; } } 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] = 1;continue; } vector<int>tmp(P.size(),0); REP(j,P.size()){ while(p%P[j] == 0){ p /= P[j]; tmp[inv[P[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; } }