結果

問題 No.854 公平なりんご分配
ユーザー edamame882edamame882
提出日時 2019-07-26 23:15:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,221 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 172,740 KB
実行使用メモリ 76,924 KB
最終ジャッジ日時 2024-07-02 09:30:36
合計ジャッジ時間 10,155 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other AC * 6 WA * 44 TLE * 1 -- * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
VI prime;

void makePrime(){
  bool p[2001];
  memset(p,true,sizeof(p));
  p[0] = false;
  p[1] = false;
  for(int i = 2; i*i <=2000; i++){
    if(p[i] == false) continue;
    int x = 2;
    while(x*i<= 2000){p[x*i] = false; x++;}
  }
  rep(i,2001) if(p[i]) prime.push_back(i);

}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  makePrime();

  int n; cin >> n;
  VLL a(n);
  rep(i,n) cin >> a[i];

  ll mul[n][prime.size()];
  memset(mul,0,sizeof(mul));
  int imos[n];
  memset(imos,0,sizeof(imos));
  rep(i,n){
    if(a[i] == 0) imos[i] = 1;
    if(i != 0){
      rep(j,prime.size()){
        mul[i][j] = mul[i-1][j];
        while(a[i] % prime[j] == 0) mul[i][j]++,a[i]/=prime[j];
      }
    }else{
      rep(j,prime.size()){
        while(a[i] % prime[j] == 0) mul[i][j]++,a[i]/=prime[j];
      }
    }
  }
  rep(i,n-1) imos[i+1] += imos[i];

  // rep(i,n){
  //   rep(j,prime.size()) cout  << mul[i][j] << " ";
  //   cout << endl;
  // }
  ll q; cin >> q;

  rep(i,q){
    ll p,l,r;
    cin >> p >> l >> r;
    l--,r--;
    bool flag = true;
    rep(j,prime.size()){
      int cnt = mul[r][j];
      if(l != 0) cnt -= mul[l-1][j];
      while(p % prime[j] == 0) cnt--, p/=prime[j];
      if(cnt < 0 ) flag = false;
    }
    int check = imos[r];
    if(l != 0) check -= imos[l-1];
    if(flag && check != 0) cout << "Yes" << "\n";
    else cout << "NO" << "\n";
  }
  return 0;
}
0