QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#79709#3724. Strange PrimelichenghanAC ✓67ms5700kbC++141.4kb2023-02-20 19:29:082023-02-20 19:29:08

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-20 19:29:08]
  • 评测
  • 测评结果:AC
  • 用时:67ms
  • 内存:5700kb
  • [2023-02-20 19:29:08]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstdlib>
#define int long long
using namespace std;
const int p=1e10+19;
const int mod=1e9+7;
// FAST IO
//#define FREAD_USED
inline char gc() {
	#ifndef FREAD_USED
	return getchar();
	#else
	const int size=100005;
	static char buf[size],*p1=buf+size,*p2=buf+size;
	if(p1==p2)p2=(p1=buf)+fread(buf,1,size,stdin);
	return p1==p2?-1:*p1++;
	#endif
}
template<typename t=int> inline t read() {
	char ch=gc();
	t sum=0,s=1;
	while(ch<'0'||ch>'9'){
		if((ch=gc())=='-')s=-1;
		if(ch==-1) exit(0);
	}
	while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=gc();
	return sum*s;
}
template<typename t> inline void write(t x){
	if(x<0) putchar('-'),x=-x;
	if(x<10){
		putchar(x+48);
		return;
	}
	write(x/10);
	putchar(x%10+48);
}
//FAST IO END
const int N=1e5+100;
int n,a[N];
int pre[N],suf[N];
signed main(){
	while(true){
		n=read();
		for(int i=1;i<=n;i++){
			a[i]=read();
		}
//		puts("hi");
		pre[0]=1;
		for(int i=1;i<=n;i++){
			pre[i]=pre[i-1]*((p-a[i])%mod)%mod;
		}
//		puts("1");
		suf[n+1]=1;
		for(int i=n;i;i--){
			suf[i]=suf[i+1]*a[i]%mod;
		}
//		puts("2");
//		for(int i=1;i<=n;i++){
//			write(pre[i]);putchar(' ');write(suf[i]);putchar('\n');
//		}
		int ans=0;
		for(int i=n;i>=1;i--){
			ans+=pre[i-1]*suf[i+1]%mod*(i%2!=n%2?-1:1);
			ans=(ans%mod+mod)%mod;
		}
//		puts("hi");
		write(ans);
		puts("");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 67ms
memory: 5700kb

input:

10
2357 42596 7212 30898 43465 68984 60783 59520 53767 77560
10
39115 88080 83553 61736 90821 39690 13194 81396 38051 55993
10
95070 81321 71632 21071 10807 46105 66844 63678 47577 75132
10
43898 93215 26791 11849 61857 1423 76971 83489 52044 61325
10
22610 16613 90 53598 80110 42651 64942 67114 242...

output:

8747181
109223012
855771490
541976436
590061154
362989597
987338731
316507988
571293823
811262072
971678511
475746045
438611414
341241863
155506989
174497292
470085592
844919405
114498965
739370426
38587099
214008686
506810838
254574502
480440711
792847181
303917854
79001517
310250674
834963010
1907...

result:

ok 11305 numbers