結果

問題 No.1261 数字集め
ユーザー 👑 kmjpkmjp
提出日時 2020-10-17 20:06:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,528 ms / 8,000 ms
コード長 2,061 bytes
コンパイル時間 2,978 ms
コンパイル使用メモリ 203,152 KB
実行使用メモリ 120,364 KB
最終ジャッジ日時 2023-09-28 11:21:55
合計ジャッジ時間 132,730 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,528 ms
120,024 KB
testcase_01 AC 523 ms
56,108 KB
testcase_02 AC 1,338 ms
90,068 KB
testcase_03 AC 1,342 ms
91,168 KB
testcase_04 AC 761 ms
67,164 KB
testcase_05 AC 1,898 ms
112,224 KB
testcase_06 AC 911 ms
72,988 KB
testcase_07 AC 1,374 ms
93,500 KB
testcase_08 AC 679 ms
63,188 KB
testcase_09 AC 967 ms
74,800 KB
testcase_10 AC 25 ms
28,896 KB
testcase_11 AC 1,902 ms
110,796 KB
testcase_12 AC 1,667 ms
102,048 KB
testcase_13 AC 1,474 ms
94,332 KB
testcase_14 AC 65 ms
33,440 KB
testcase_15 AC 620 ms
58,988 KB
testcase_16 AC 1,491 ms
93,596 KB
testcase_17 AC 1,157 ms
79,872 KB
testcase_18 AC 648 ms
59,600 KB
testcase_19 AC 1,402 ms
91,276 KB
testcase_20 AC 85 ms
35,200 KB
testcase_21 AC 2,148 ms
116,080 KB
testcase_22 AC 1,984 ms
118,056 KB
testcase_23 AC 1,972 ms
117,964 KB
testcase_24 AC 1,937 ms
120,232 KB
testcase_25 AC 1,964 ms
120,036 KB
testcase_26 AC 1,960 ms
120,056 KB
testcase_27 AC 1,978 ms
120,156 KB
testcase_28 AC 1,964 ms
120,196 KB
testcase_29 AC 1,966 ms
120,108 KB
testcase_30 AC 1,978 ms
120,060 KB
testcase_31 AC 1,896 ms
120,028 KB
testcase_32 AC 1,874 ms
120,020 KB
testcase_33 AC 1,939 ms
120,156 KB
testcase_34 AC 1,909 ms
120,024 KB
testcase_35 AC 1,910 ms
120,156 KB
testcase_36 AC 2,003 ms
120,076 KB
testcase_37 AC 1,894 ms
120,040 KB
testcase_38 AC 1,866 ms
120,008 KB
testcase_39 AC 1,901 ms
120,060 KB
testcase_40 AC 1,906 ms
120,020 KB
testcase_41 AC 1,953 ms
120,092 KB
testcase_42 AC 1,931 ms
120,100 KB
testcase_43 AC 2,015 ms
120,116 KB
testcase_44 AC 1,738 ms
109,156 KB
testcase_45 AC 258 ms
45,468 KB
testcase_46 AC 796 ms
71,676 KB
testcase_47 AC 515 ms
60,984 KB
testcase_48 AC 1,352 ms
96,180 KB
testcase_49 AC 1,641 ms
108,212 KB
testcase_50 AC 1,483 ms
99,728 KB
testcase_51 AC 276 ms
47,676 KB
testcase_52 AC 32 ms
31,092 KB
testcase_53 AC 329 ms
47,724 KB
testcase_54 AC 380 ms
50,372 KB
testcase_55 AC 121 ms
39,248 KB
testcase_56 AC 200 ms
42,004 KB
testcase_57 AC 1,269 ms
92,820 KB
testcase_58 AC 261 ms
45,864 KB
testcase_59 AC 1,703 ms
110,480 KB
testcase_60 AC 348 ms
51,756 KB
testcase_61 AC 539 ms
60,772 KB
testcase_62 AC 1,549 ms
101,960 KB
testcase_63 AC 136 ms
40,664 KB
testcase_64 AC 1,959 ms
116,884 KB
testcase_65 AC 1,158 ms
87,212 KB
testcase_66 AC 941 ms
78,304 KB
testcase_67 AC 1,548 ms
102,844 KB
testcase_68 AC 887 ms
75,764 KB
testcase_69 AC 837 ms
73,320 KB
testcase_70 AC 671 ms
66,004 KB
testcase_71 AC 1,454 ms
98,624 KB
testcase_72 AC 411 ms
56,476 KB
testcase_73 AC 504 ms
58,708 KB
testcase_74 AC 152 ms
42,232 KB
testcase_75 AC 810 ms
70,936 KB
testcase_76 AC 1,291 ms
92,936 KB
testcase_77 AC 1,558 ms
103,256 KB
testcase_78 AC 33 ms
30,144 KB
testcase_79 AC 1,632 ms
106,176 KB
testcase_80 AC 50 ms
30,992 KB
testcase_81 AC 81 ms
36,568 KB
testcase_82 AC 1,220 ms
89,432 KB
testcase_83 AC 432 ms
57,788 KB
testcase_84 AC 2,019 ms
120,112 KB
testcase_85 AC 2,015 ms
120,144 KB
testcase_86 AC 2,027 ms
120,224 KB
testcase_87 AC 1,968 ms
120,132 KB
testcase_88 AC 1,959 ms
120,156 KB
testcase_89 AC 2,041 ms
120,096 KB
testcase_90 AC 2,031 ms
120,092 KB
testcase_91 AC 2,016 ms
120,076 KB
testcase_92 AC 2,028 ms
120,364 KB
testcase_93 AC 1,962 ms
120,116 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];
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]--;
	}
	ll ret=0;
	for(i=2;i<=N;i++) {
		for(j=2*i;j<=N;j+=i) {
			if(j==N) EN[i]=1;
			if(j<N&&N%j==0) ret+=hoge(A[i],A[j],A[N],M);
			R[j].push_back(i);
		}
	}
	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