結果
問題 | No.854 公平なりんご分配 |
ユーザー |
![]() |
提出日時 | 2019-07-27 08:36:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,510 ms / 3,153 ms |
コード長 | 2,046 bytes |
コンパイル時間 | 1,565 ms |
コンパイル使用メモリ | 163,992 KB |
実行使用メモリ | 243,840 KB |
最終ジャッジ日時 | 2024-07-02 10:47:22 |
合計ジャッジ時間 | 29,361 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 92 |
ソースコード
#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; }