結果

問題 No.854 公平なりんご分配
ユーザー NyaanNyaanNyaanNyaan
提出日時 2019-07-26 23:31:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 9,435 bytes
コンパイル時間 2,910 ms
コンパイル使用メモリ 129,252 KB
実行使用メモリ 361,048 KB
最終ジャッジ日時 2023-09-15 05:01:21
合計ジャッジ時間 20,892 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,388 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 5 ms
4,384 KB
testcase_23 AC 6 ms
5,044 KB
testcase_24 AC 8 ms
6,464 KB
testcase_25 AC 4 ms
4,520 KB
testcase_26 AC 8 ms
6,452 KB
testcase_27 AC 8 ms
6,724 KB
testcase_28 AC 5 ms
4,380 KB
testcase_29 AC 4 ms
4,384 KB
testcase_30 AC 5 ms
4,768 KB
testcase_31 AC 8 ms
6,168 KB
testcase_32 AC 121 ms
79,320 KB
testcase_33 AC 84 ms
43,412 KB
testcase_34 AC 178 ms
107,004 KB
testcase_35 AC 138 ms
85,136 KB
testcase_36 AC 43 ms
8,052 KB
testcase_37 AC 106 ms
74,132 KB
testcase_38 AC 82 ms
60,308 KB
testcase_39 AC 230 ms
114,108 KB
testcase_40 AC 83 ms
37,572 KB
testcase_41 AC 119 ms
68,752 KB
testcase_42 AC 165 ms
106,520 KB
testcase_43 AC 147 ms
72,264 KB
testcase_44 AC 176 ms
97,864 KB
testcase_45 AC 102 ms
21,424 KB
testcase_46 AC 200 ms
97,668 KB
testcase_47 AC 90 ms
54,732 KB
testcase_48 AC 157 ms
104,608 KB
testcase_49 AC 155 ms
106,504 KB
testcase_50 AC 99 ms
73,896 KB
testcase_51 AC 202 ms
101,832 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 MLE -
testcase_83 MLE -
testcase_84 MLE -
testcase_85 MLE -
testcase_86 MLE -
testcase_87 MLE -
testcase_88 MLE -
testcase_89 MLE -
testcase_90 MLE -
testcase_91 MLE -
testcase_92 MLE -
testcase_93 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O2")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define whlie while
#define retunr return
#define reutrn return
#define reutnr return
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define inf 1001001001
#define MOD 998244353
#define infLL (1LL << 61)
#define FOR(i,a,b) for(int (i)=(int)(a); (i)<(int)(b); (i)++) // [a,b)
#define rep(i,N) FOR((i), 0, (int)(N)) // [0,N)
#define FORR(i,a,b) for(int (i)=(int)(b) - 1; (i)>=(int)(a); (i)--)
#define repr(i,N) FORR((i), 0, (int)(N))
#define each(x,v) for(auto &x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it=v.begin();it!=v.end();it++)
#define vrepr(v,it) for(auto it=v.rbegin();it!=v.rend();it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) double __VA_ARGS__; in(__VA_ARGS__)
#define inpii(...) pii __VA_ARGS__; in(__VA_ARGS__)
//#define rand mtrand
//#define randinit random_device seed_gen; mt19937_64 mtrand(seed_gen())

#ifdef LOCAL  
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define stopif(val) assert( !(val) )
  #define trcv(v,...) do { cout << #v << " = "; vector_debug(v , ##__VA_ARGS__);cout << endl;} while(0)
#else
  #define trc(...)
  #define stopif(...)
  #define trcv(...)
#endif

using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector< vector<int> >;

struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
/* 
int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);} ll gcd(ll a, ll b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}
ll lcm(int a, int b){return (1LL * a / gcd(a,b)) * b;} ll lcm(ll a, ll b){return (a / gcd(a,b)) * b;}
*/
inline ll pow(int a, int b){ll ans = 1; rep(i,b) ans *= a; return ans;} inline ll pow(ll a, ll b){ll ans = 1; rep(i,b) ans*= a; return ans;}
inline ll pow(int a, ll b){ll ans = 1; rep(i,b) ans *= a; return ans;} inline ll pow(ll a, int b){ll ans = 1; rep(i,b) ans*= a; return ans;}
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename C> inline void _cin(C &c){cin >> c;}
template<typename T,typename U> inline void _cin(pair<T,U> &p){cin >> p.fi; cin >> p.se;}
template<typename C> inline void _cout(const C &c){cout << c;}
template<typename T,typename U> inline void _cout(const pair<T,U> &p){cout << p.fi << ' ' << p.se;}
void in(){} template <typename T,class... U> void in(T &t,U &...u){ _cin(t); in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,U ...u){ _cout(t); if(sizeof...(u)) cout << ' '; out(u...);}
template<typename C> inline void in(vector<C> &v,int N=-1){if(sz(v) != 0){int M=(N == -1) ? sz(v) : N; rep(i,M) _cin(v[i]);}else{C c;rep(i,N) v.pb((_cin(c),c));}}
template<typename C> inline void in(C v[],int N){rep(i,N) _cin(v[i]);}
template<typename C> inline void out(const vector<C> &v,int N=-1){int M=(N == -1) ? sz(v) : N; rep(i,M) {cout<<( (i)?" ":"" ); _cout(v[i]);} cout<<"\n";}
template<typename C> inline void out(C v[],int N){rep(i,N) {cout<<( (i)?" ":"" ); _cout(v[i]);} cout<<"\n";}
template<typename C> inline void vector_debug(const vector<C> &v,int N=-1){cout << "{"; int M=(N == -1) ? sz(v) : N; rep(i,M) {cout<<( (i)?", ":"" ); _cout(v[i]);} cout<<"}";}
template<typename C> inline void vector_debug(C v[], int N){cout << "{"; rep(i,N) {cout<<((i)?", ":""); _cout(*(v+i));} cout<<"}";}
void dbg_out(){cout << endl;} template <typename T,class... U> void dbg_out(const T &t,U ...u){ _cout(t); if(sizeof...(u)) cout << ", "; dbg_out(u...);}
template<typename C,class... U> void dbg_out(const vector<C> &v,U ...u){vector_debug(v); if(sizeof...(u)) cout << ", "; dbg_out(u...);}
template<typename C,class... U> void dbg_out(const vector<vector<C>> &v,U ...u){cout << "{ "; rep(i,sz(v)) {if(i)cout<<", "; vector_debug(v[i]);} cout << " }"; if(sizeof...(u)) cout << ", "; dbg_out(u...);}
template<typename C> inline C vmax(const vector<C> &v){C n=v[0]; rep(i,sz(v)) amax(n,v[i]); return n;} template<typename C> inline C vmax(C v[], int N){C n=v[0]; rep( i , N ) amax(n,v[i]); return n;}
template<typename C> inline C vmin(const vector<C> &v){C n=v[0]; rep(i,sz(v)) amin(n,v[i]); return n;} template<typename C> inline C vmin(C v[], int N){C n=v[0]; rep( i , N ) amin(n,v[i]); return n;}
void die(string s){out(s); exit(0);}

////////////
/// main ///
////////////

// 1からNまでの素数を判定するライブラリ
// A[i] == 1 <-> iは素数
void prime(vi& A,int N){
    rep(i,N + 1) A[i] = 1;
    A[0] = 0; A[1] = 0;
    for(int i=2 ; i*i <= N ; i++){
        if(A[i]){
            for(int j=2; i*j <= N; j++){
                A[i*j] = 0;
            }
        }
    }
}
// 省メモリセグ木 使いどころある? ないですね(完)
template<typename T,typename F,T UNIT>
struct ST{
  int size;
  vector<T> seg;
  F func;
  vector<int> seg_sz;

  ST(){};
  ST(const vector<T> &v,F func) : func(func){
    // initialize
    seg.resize( ( size = v.size() ) << 1 , UNIT);
    // set
    // n A[n]まで見た
    int n = 0; seg_sz.pb(0);
    while(n < size){
      // これからm個の配列を埋める
      int m = 1 << (31 - __builtin_clz(size ^ n) );
      for(int i = n; i < n + m; i++){
        //trc(n , m , i);
        seg[n + m + i] = v[i];
      }
      seg_sz.pb( (n += m) );
    }
    //
    build();
  }

  void build(){
    vector<int>::const_iterator it = seg_sz.begin();
    while(1){
      int l = *(it++);
      if(it == seg_sz.end()) return;
      int r = *it;
      const int dif = l << 1; // k 添え字のズレ
      for( int i = r - l - 1; i > 0; i-- ){
        seg[dif | i] = func(seg[dif | (i << 1)] , seg[dif | (i << 1) | 1]);
      }
    }    
  }
  
  void update(int k, T& x){
    vector<int>::const_iterator it = upper_bound(seg_sz.begin() , seg_sz.end() , k);
    seg[ (k += *it) ] = x; 
    it--; k -= (*it) << 1; const int dif = (*it) << 1;
    //trc(k , dif);
    // [*it , *(it + 1) ) 間のセグ木を更新 添え字はdifずれている
    while(k >>= 1){
      seg[dif | k] = func(seg[dif | (k << 1)] , seg[dif | (k << 1) | 1]);
    }
  }
  // [a,b)へのクエリ
  T query(int a, int b){
    //trc("query" , a , b);
    if(a < 0){a = 0;} b--; // いったん閉区間にする
    
    // おなじセグ木に乗せる処理
    T ret = UNIT;
    vector<int>::const_iterator itl = upper_bound(seg_sz.begin() , seg_sz.end() , a),
      itr = upper_bound(seg_sz.begin() , seg_sz.end() , b);
    itl--; const int cur_sz = *(itr--) - *itr;// 右側の載っているセグ木のサイズ
    //trc(ret , *itl , *itr);
    while(itl != itr) {
      if(a == *itl) ret = func(ret , seg[ ( (*itl++) << 1 ) | 1 ]);
      else ret = func(ret , query(a , (*(++itl))) );
      a = *itl;
      //trc(ret , *itl , *itr);
    }
    const int dif = (*itr) << 1;
    // 普通のセグ木の処理 セグ木のサイズはcur_sz a,bは添え字はdifずれる
    T L = UNIT, R = UNIT;
    for( a += cur_sz - *itr , b += cur_sz + 1 - *itr ; a<b; a>>=1,b>>=1){
      if(a & 1) L = func(L,seg[dif | (a++)]);
      if(b & 1) R = func(seg[dif | (--b)],R);
    }
    return func(ret , func(L, R) );
  }

  T operator[](const int &k) const{
    vector<int>::const_iterator it = upper_bound(seg_sz.begin() , seg_sz.end() , k);
    return seg[ *it + k ];
  }

};

auto f = [](int a,int b){return a + b;};

int main(){
  ini(N);
  vi a(N);
  in(a,N);
  ini(Q);
  vi P(Q),L(Q),R(Q);
  rep(i,Q) in(P[i],L[i],R[i]);
  vi A(2001);
  prime(A , 2000);
  vi lst;
  lst.reserve(1000);
  int nyanya = 0;
  rep(i,2001) if(A[i] == 1) {
    A[i] = nyanya++;
    lst.pb(i);
  }
  trc(sz(lst));
  vvi data(303 , vi(N , 0));
  rep(i,N){
    rep(j,303){
      if(a[i] == 0) data[j][i] = -20000;
      else while(a[i] % lst[j] == 0){
        data[j][i]++;
        a[i] /= lst[j]; 
      }
    }
  }
  //out("hoe");
  vector< ST<int , decltype(f) , 0> > st;
  st.reserve(303);
  rep(i,303){
    st.pb(ST<int , decltype(f) , 0>(data[i] , f));
  }

  rep(i,Q){
    int hoge = P[i];
    rep(j,303){
      int p = lst[j];
      while(hoge % p == 0) hoge /= p;
    }
    if(hoge != 1) {out("NO"); continue;}
    repr(j,303){
      int p = lst[j];
      if(p > P[i]) continue;
      if(P[i] == 1) break;
      if(P[i] % p != 0) continue;
      int cur = st[j].query(L[i] - 1 , R[i]);
      while(cur > 0){
        if(P[i] % p != 0) break;
        P[i] /= p; cur--;
      }
      if(P[i] == 1 || P[i] % p == 0) break;
    }
    out(P[i] == 1 ? "Yes" : "NO");
  }

}
0