結果

問題 No.854 公平なりんご分配
ユーザー DAyamaCTFDAyamaCTF
提出日時 2019-07-27 08:36:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,586 ms / 3,153 ms
コード長 2,046 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 150,552 KB
実行使用メモリ 243,948 KB
最終ジャッジ日時 2023-09-15 05:56:12
合計ジャッジ時間 32,785 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,768 KB
testcase_01 AC 4 ms
5,752 KB
testcase_02 AC 4 ms
5,740 KB
testcase_03 AC 3 ms
5,748 KB
testcase_04 AC 3 ms
5,792 KB
testcase_05 AC 4 ms
5,756 KB
testcase_06 AC 4 ms
5,860 KB
testcase_07 AC 4 ms
5,744 KB
testcase_08 AC 4 ms
5,804 KB
testcase_09 AC 3 ms
5,744 KB
testcase_10 AC 4 ms
5,856 KB
testcase_11 AC 3 ms
6,000 KB
testcase_12 AC 5 ms
5,832 KB
testcase_13 AC 4 ms
5,816 KB
testcase_14 AC 4 ms
5,924 KB
testcase_15 AC 4 ms
5,796 KB
testcase_16 AC 4 ms
5,828 KB
testcase_17 AC 5 ms
5,852 KB
testcase_18 AC 4 ms
5,848 KB
testcase_19 AC 4 ms
5,820 KB
testcase_20 AC 4 ms
5,956 KB
testcase_21 AC 5 ms
5,844 KB
testcase_22 AC 11 ms
6,204 KB
testcase_23 AC 11 ms
6,928 KB
testcase_24 AC 17 ms
7,828 KB
testcase_25 AC 9 ms
6,764 KB
testcase_26 AC 17 ms
7,916 KB
testcase_27 AC 15 ms
7,952 KB
testcase_28 AC 9 ms
6,216 KB
testcase_29 AC 6 ms
6,240 KB
testcase_30 AC 9 ms
6,660 KB
testcase_31 AC 16 ms
7,536 KB
testcase_32 AC 210 ms
56,040 KB
testcase_33 AC 175 ms
32,576 KB
testcase_34 AC 351 ms
75,080 KB
testcase_35 AC 259 ms
60,232 KB
testcase_36 AC 107 ms
8,896 KB
testcase_37 AC 196 ms
52,848 KB
testcase_38 AC 157 ms
43,940 KB
testcase_39 AC 471 ms
79,512 KB
testcase_40 AC 183 ms
28,596 KB
testcase_41 AC 239 ms
49,328 KB
testcase_42 AC 328 ms
73,948 KB
testcase_43 AC 318 ms
51,328 KB
testcase_44 AC 371 ms
68,836 KB
testcase_45 AC 261 ms
17,712 KB
testcase_46 AC 430 ms
67,888 KB
testcase_47 AC 185 ms
40,280 KB
testcase_48 AC 306 ms
72,808 KB
testcase_49 AC 301 ms
74,308 KB
testcase_50 AC 188 ms
52,512 KB
testcase_51 AC 441 ms
71,268 KB
testcase_52 AC 240 ms
34,080 KB
testcase_53 AC 153 ms
33,564 KB
testcase_54 AC 250 ms
39,492 KB
testcase_55 AC 124 ms
33,696 KB
testcase_56 AC 124 ms
35,124 KB
testcase_57 AC 148 ms
29,492 KB
testcase_58 AC 220 ms
15,160 KB
testcase_59 AC 95 ms
26,272 KB
testcase_60 AC 177 ms
29,436 KB
testcase_61 AC 70 ms
9,924 KB
testcase_62 AC 194 ms
25,516 KB
testcase_63 AC 143 ms
26,792 KB
testcase_64 AC 61 ms
13,620 KB
testcase_65 AC 246 ms
65,516 KB
testcase_66 AC 121 ms
20,640 KB
testcase_67 AC 223 ms
43,880 KB
testcase_68 AC 174 ms
21,708 KB
testcase_69 AC 274 ms
79,580 KB
testcase_70 AC 106 ms
28,964 KB
testcase_71 AC 119 ms
31,232 KB
testcase_72 AC 142 ms
9,028 KB
testcase_73 AC 194 ms
53,616 KB
testcase_74 AC 301 ms
64,332 KB
testcase_75 AC 155 ms
31,508 KB
testcase_76 AC 227 ms
51,232 KB
testcase_77 AC 298 ms
72,484 KB
testcase_78 AC 236 ms
23,628 KB
testcase_79 AC 254 ms
45,028 KB
testcase_80 AC 250 ms
47,404 KB
testcase_81 AC 206 ms
49,256 KB
testcase_82 AC 1,107 ms
243,820 KB
testcase_83 AC 1,460 ms
243,820 KB
testcase_84 AC 1,449 ms
243,816 KB
testcase_85 AC 1,509 ms
243,816 KB
testcase_86 AC 674 ms
243,808 KB
testcase_87 AC 1,019 ms
243,888 KB
testcase_88 AC 1,019 ms
243,892 KB
testcase_89 AC 1,029 ms
243,880 KB
testcase_90 AC 1,025 ms
243,948 KB
testcase_91 AC 1,025 ms
243,876 KB
testcase_92 AC 1,582 ms
243,828 KB
testcase_93 AC 1,586 ms
243,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

vector<ll> operator+(const vector<ll>& a,const vector<ll>& b){
  vector<ll> res(a.size(),0);
  rep(i,a.size())res[i]=a[i]+b[i];
  return res;
}
vector<ll> operator-(const vector<ll>& a,const vector<ll>& b){
  vector<ll> res(a.size(),0);
  rep(i,a.size())res[i]=a[i]-b[i];
  return res;
}

bool isprime[2001];
vector<ll> ps;
ll M;
vector<ll> calcvec(ll X){
  if(X==0) return vector<ll>(M,0);

  vector<ll> res(M,0);
  rep(i,ps.size()){
    while(X%ps[i]==0){
      res[i]++;
      X/=ps[i];
    }
  }
  if(X!=1) return vector<ll>(1,-1);
  return res;
}

ll N,Q;
vector<ll> sum[100010];
ll zsum[100010];

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

  repl(i,2,2001)isprime[i]=true;
  for(ll i=2;i<=2000;i++){
    if(isprime[i]){
      ps.push_back(i);
      for(ll j=i*2;j<=2000;j+=i)isprime[j]=false;
    }
  }
  M=ps.size();

  sum[0]=vector<ll>(M,0);
  cin>>N;
  rep(i,N){
    ll A;
    cin>>A;
    if(A==0){
      zsum[i+1]=zsum[i]+1;
    }else{
      zsum[i+1]=zsum[i];
    }
    vector<ll> B=calcvec(A);
    sum[i+1]=sum[i]+B;
  }

  cin>>Q;
  rep(i,Q){
    ll P,L,R;
    cin>>P>>L>>R;
    L--;
    if(zsum[R]-zsum[L]>0){
      cout<<"Yes"<<endl;
      continue;
    }
    vector<ll> tmp=sum[R]-sum[L];
    vector<ll> p=calcvec(P);
    if(p[0]==-1){
      cout<<"NO"<<endl;
      continue;
    }
    bool ok=true;
    rep(j,M)if(tmp[j]<p[j])ok=false;
    if(ok) cout<<"Yes"<<endl;
    else cout<<"NO"<<endl;
  }

  return 0;
}
0