結果

問題 No.1261 数字集め
ユーザー 👑 kmjpkmjp
提出日時 2020-10-17 20:04:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,202 ms / 8,000 ms
コード長 2,123 bytes
コンパイル時間 2,407 ms
コンパイル使用メモリ 204,216 KB
実行使用メモリ 207,428 KB
最終ジャッジ日時 2023-09-28 11:17:36
合計ジャッジ時間 180,617 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,202 ms
207,100 KB
testcase_01 AC 728 ms
102,428 KB
testcase_02 AC 1,803 ms
160,564 KB
testcase_03 AC 1,845 ms
161,840 KB
testcase_04 AC 1,081 ms
121,224 KB
testcase_05 AC 2,536 ms
200,392 KB
testcase_06 AC 1,264 ms
130,976 KB
testcase_07 AC 1,948 ms
165,872 KB
testcase_08 AC 936 ms
114,164 KB
testcase_09 AC 1,361 ms
133,984 KB
testcase_10 AC 35 ms
57,488 KB
testcase_11 AC 2,497 ms
196,516 KB
testcase_12 AC 2,255 ms
180,472 KB
testcase_13 AC 1,963 ms
167,520 KB
testcase_14 AC 88 ms
64,952 KB
testcase_15 AC 798 ms
106,908 KB
testcase_16 AC 1,916 ms
166,404 KB
testcase_17 AC 1,485 ms
143,236 KB
testcase_18 AC 858 ms
108,044 KB
testcase_19 AC 1,853 ms
162,412 KB
testcase_20 AC 112 ms
67,608 KB
testcase_21 AC 2,686 ms
205,220 KB
testcase_22 AC 2,673 ms
205,188 KB
testcase_23 AC 2,608 ms
205,148 KB
testcase_24 AC 2,621 ms
205,360 KB
testcase_25 AC 2,743 ms
205,260 KB
testcase_26 AC 2,740 ms
205,256 KB
testcase_27 AC 2,711 ms
205,252 KB
testcase_28 AC 2,761 ms
205,540 KB
testcase_29 AC 2,709 ms
205,276 KB
testcase_30 AC 2,713 ms
205,360 KB
testcase_31 AC 2,737 ms
207,156 KB
testcase_32 AC 2,728 ms
205,348 KB
testcase_33 AC 2,721 ms
205,248 KB
testcase_34 AC 2,619 ms
205,260 KB
testcase_35 AC 2,671 ms
207,180 KB
testcase_36 AC 2,735 ms
207,428 KB
testcase_37 AC 2,783 ms
207,148 KB
testcase_38 AC 2,758 ms
207,424 KB
testcase_39 AC 2,738 ms
207,264 KB
testcase_40 AC 2,744 ms
207,160 KB
testcase_41 AC 2,758 ms
207,176 KB
testcase_42 AC 2,759 ms
207,236 KB
testcase_43 AC 2,739 ms
207,140 KB
testcase_44 AC 2,385 ms
187,852 KB
testcase_45 AC 371 ms
81,140 KB
testcase_46 AC 1,108 ms
123,560 KB
testcase_47 AC 727 ms
101,184 KB
testcase_48 AC 1,910 ms
165,092 KB
testcase_49 AC 2,365 ms
186,000 KB
testcase_50 AC 2,082 ms
171,424 KB
testcase_51 AC 422 ms
84,924 KB
testcase_52 AC 44 ms
56,432 KB
testcase_53 AC 442 ms
85,128 KB
testcase_54 AC 548 ms
89,556 KB
testcase_55 AC 174 ms
70,596 KB
testcase_56 AC 269 ms
75,108 KB
testcase_57 AC 1,813 ms
158,596 KB
testcase_58 AC 381 ms
81,984 KB
testcase_59 AC 2,476 ms
190,620 KB
testcase_60 AC 519 ms
88,632 KB
testcase_61 AC 810 ms
103,292 KB
testcase_62 AC 2,196 ms
175,420 KB
testcase_63 AC 205 ms
72,960 KB
testcase_64 AC 2,675 ms
201,736 KB
testcase_65 AC 1,643 ms
148,584 KB
testcase_66 AC 1,316 ms
131,824 KB
testcase_67 AC 2,144 ms
175,660 KB
testcase_68 AC 1,242 ms
127,392 KB
testcase_69 AC 1,176 ms
125,440 KB
testcase_70 AC 897 ms
109,912 KB
testcase_71 AC 1,971 ms
169,412 KB
testcase_72 AC 557 ms
93,216 KB
testcase_73 AC 697 ms
100,160 KB
testcase_74 AC 224 ms
75,520 KB
testcase_75 AC 1,115 ms
120,636 KB
testcase_76 AC 1,823 ms
159,136 KB
testcase_77 AC 2,186 ms
177,588 KB
testcase_78 AC 42 ms
54,816 KB
testcase_79 AC 2,292 ms
182,672 KB
testcase_80 AC 61 ms
56,192 KB
testcase_81 AC 120 ms
65,920 KB
testcase_82 AC 1,694 ms
152,636 KB
testcase_83 AC 646 ms
95,640 KB
testcase_84 AC 2,799 ms
207,324 KB
testcase_85 AC 2,786 ms
207,136 KB
testcase_86 AC 2,794 ms
207,264 KB
testcase_87 AC 2,859 ms
207,184 KB
testcase_88 AC 2,820 ms
207,200 KB
testcase_89 AC 2,782 ms
207,216 KB
testcase_90 AC 2,790 ms
207,192 KB
testcase_91 AC 2,829 ms
207,152 KB
testcase_92 AC 2,798 ms
207,208 KB
testcase_93 AC 2,811 ms
207,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
const ll mo=1000000007;
int A[1010101];
int EN[1010101];
vector<int> R[1010101],E[1010101];
int Q,X,Y;
ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll hoge(ll a,ll b,ll c,ll m) {
	if(a>b) swap(a,b);
	if(b>c) swap(b,c);
	if(a>b) swap(a,b);
	if(a==c) {
		ll ret=modpow(a,M);
		//comb(m+2,2)
		return ret*((m+2)*(m+1)/2%mo)%mo;
	}
	else if(a==b) {
		ll p=modpow(a,M+1)-modpow(c,M+1)+mo;
		ll q=(mo+c-a)*(a+mo-c)%mo;
		return p*c%mo*modpow(q)%mo;
	}
	else if(b==c) {
		ll p=modpow(a,M+1)-modpow(c,M+1)+mo;
		ll q=(mo+c-a)*(a+mo-c)%mo;
		return p*a%mo*modpow(q)%mo;
	}
	ll A=modpow(a,M+2)*(mo+b-c)%mo;
	ll B=modpow(b,M+2)*(mo+c-a)%mo;
	ll C=modpow(c,M+2)*(mo+a-b)%mo;
	ll ret=A+B+C;
	ll q=(mo+a-b)*(mo+b-c)%mo*(mo+c-a)%mo;
	return ret*modpow(mo-q)%mo;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	M-=3;
	for(i=2;i<=N;i++) {
		cin>>A[i];
		A[i]--;
	}
	for(i=2;i<=N;i++) {
		for(j=2*i;j<=N;j+=i) {
			if(j==N) EN[i]=1;
			E[i].push_back(j);
			R[j].push_back(i);
		}
	}
	ll ret=0;
	for(i=2;i<N;i++) {
		FORR(e,E[i]) if(EN[e]) ret+=hoge(A[i],A[e],A[N],M);
	}
	ret%=mo;
	cout<<ret<<endl;
	
	cin>>Q;
	while(Q--) {
		cin>>X>>Y;
		
		if(Y<N) {
			if(EN[Y]) (ret+=hoge(A[X],A[Y],A[N],M))%=mo;
		}
		else {
			FORR(p,R[X]) (ret+=hoge(A[p],A[X],A[N],M))%=mo;
		}
		cout<<ret<<endl;
		if(Y==N) EN[X]=1;
		R[Y].push_back(X);
		
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0