結果

問題 No.854 公平なりんご分配
ユーザー ahe100ahe100
提出日時 2019-07-26 23:02:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,562 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 169,552 KB
実行使用メモリ 126,860 KB
最終ジャッジ日時 2023-09-15 03:47:49
合計ジャッジ時間 26,644 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
7,804 KB
testcase_01 AC 10 ms
7,476 KB
testcase_02 AC 10 ms
7,476 KB
testcase_03 AC 10 ms
7,480 KB
testcase_04 AC 10 ms
7,528 KB
testcase_05 AC 10 ms
7,520 KB
testcase_06 AC 9 ms
7,644 KB
testcase_07 AC 10 ms
7,532 KB
testcase_08 AC 10 ms
7,464 KB
testcase_09 AC 10 ms
7,676 KB
testcase_10 AC 10 ms
7,604 KB
testcase_11 AC 9 ms
7,608 KB
testcase_12 AC 10 ms
7,572 KB
testcase_13 AC 10 ms
7,608 KB
testcase_14 AC 9 ms
7,548 KB
testcase_15 AC 10 ms
7,504 KB
testcase_16 AC 10 ms
7,568 KB
testcase_17 AC 10 ms
7,652 KB
testcase_18 AC 10 ms
7,552 KB
testcase_19 AC 10 ms
7,544 KB
testcase_20 AC 10 ms
7,616 KB
testcase_21 AC 10 ms
7,620 KB
testcase_22 AC 15 ms
7,772 KB
testcase_23 AC 14 ms
8,204 KB
testcase_24 AC 19 ms
8,596 KB
testcase_25 AC 13 ms
8,064 KB
testcase_26 AC 20 ms
8,640 KB
testcase_27 AC 14 ms
8,744 KB
testcase_28 AC 15 ms
7,816 KB
testcase_29 AC 11 ms
7,808 KB
testcase_30 AC 13 ms
8,060 KB
testcase_31 AC 20 ms
8,664 KB
testcase_32 AC 137 ms
33,928 KB
testcase_33 AC 316 ms
21,624 KB
testcase_34 AC 578 ms
44,476 KB
testcase_35 AC 348 ms
36,232 KB
testcase_36 AC 196 ms
9,176 KB
testcase_37 AC 139 ms
31,816 KB
testcase_38 AC 85 ms
27,712 KB
testcase_39 AC 1,153 ms
46,252 KB
testcase_40 AC 394 ms
19,500 KB
testcase_41 AC 398 ms
29,824 KB
testcase_42 AC 444 ms
42,112 KB
testcase_43 AC 796 ms
31,828 KB
testcase_44 AC 780 ms
40,096 KB
testcase_45 AC 693 ms
15,304 KB
testcase_46 AC 1,150 ms
40,124 KB
testcase_47 AC 276 ms
25,748 KB
testcase_48 AC 368 ms
42,088 KB
testcase_49 AC 303 ms
42,108 KB
testcase_50 AC 96 ms
31,792 KB
testcase_51 AC 1,100 ms
42,180 KB
testcase_52 AC 371 ms
23,544 KB
testcase_53 AC 116 ms
23,612 KB
testcase_54 AC 372 ms
25,636 KB
testcase_55 AC 47 ms
23,816 KB
testcase_56 AC 51 ms
23,608 KB
testcase_57 AC 183 ms
21,532 KB
testcase_58 AC 476 ms
13,244 KB
testcase_59 AC 52 ms
19,404 KB
testcase_60 AC 263 ms
21,484 KB
testcase_61 AC 91 ms
11,160 KB
testcase_62 AC 355 ms
19,488 KB
testcase_63 AC 117 ms
19,532 KB
testcase_64 AC 69 ms
13,300 KB
testcase_65 AC 132 ms
37,964 KB
testcase_66 AC 156 ms
15,368 KB
testcase_67 AC 199 ms
27,740 KB
testcase_68 AC 234 ms
17,388 KB
testcase_69 AC 40 ms
46,380 KB
testcase_70 AC 43 ms
19,560 KB
testcase_71 AC 54 ms
21,492 KB
testcase_72 AC 255 ms
11,156 KB
testcase_73 AC 49 ms
31,876 KB
testcase_74 AC 255 ms
38,016 KB
testcase_75 AC 180 ms
21,612 KB
testcase_76 AC 106 ms
31,796 KB
testcase_77 AC 114 ms
42,232 KB
testcase_78 AC 477 ms
17,504 KB
testcase_79 AC 292 ms
27,680 KB
testcase_80 AC 296 ms
29,752 KB
testcase_81 AC 104 ms
29,800 KB
testcase_82 AC 170 ms
126,860 KB
testcase_83 TLE -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)

/*
何故かエラー出る
	解決。配列範囲には気をつけよう
*/

int n,m,a[100010],q,p[100010];
int l[100010],r[100010],fact[2010][305],dp[100010][305],zero[100010];
vector<ll> prime;

void prime_list(ll n,vector<ll>& prime_){
	ll visited[2010]={};
	reg(i,2,n){
		if(visited[i]==0){
			prime_.push_back(i);
			reg(j,2,n){
				if(j*i>n)break;
				visited[i*j]=1;
			}
		}
	}
}
ll modpow(__int128_t a, ll n,ll mo) {
	__int128_t r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void init(){
	cin>>n;
	reg(i,1,n)cin>>a[i];
	cin>>q;
	rep(i,q)cin>>p[i]>>l[i]>>r[i];
	prime_list(2000,prime);
	m = prime.size();
	rep(j,m)fact[0][j]=0;
	reg(i,1,2000){
		ll t = i;
		rep(j,m){
			fact[i][j]=0;
			while(t%prime[j]==0){
				// if(prime[j]>=45)
				t/=prime[j];
				fact[i][j]++;
			}
		}
	}
	// 12ms
	zero[0]=0;
	rep(j,m)dp[0][j]=0;
	for(int i=1;i<=n;++i){
		zero[i]=zero[i-1];
		if(a[i]==0)zero[i]++;
		for(int j=m-1;j>=0;--j)dp[i][j] = dp[i-1][j] + fact[a[i]][j];
	}
}

int main(void){
	init();
	for(int i=0;i<q;++i){
		ll tmp=1;
		if(zero[r[i]]-zero[l[i]-1]>0)tmp=0;
		for(int j=m-1;j>=0;--j){
			if(tmp==0)break;
			tmp *= modpow(prime[j], dp[r[i]][j] - dp[l[i]-1][j], p[i]);
			tmp %= p[i];
		}
		cout<<(tmp==0?"Yes":"NO")<<"\n";
	}
	return 0;
}
0