QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#754616#9738. Make It Divisibleelectricstick#WA 12ms11180kbC++172.2kb2024-11-16 15:24:472024-11-16 15:24:47

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-16 15:24:47]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:11180kb
  • [2024-11-16 15:24:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int _=1e2;
const int maxn=5e4+_;

int n,K;
int a[maxn];

int Bin[25],Log[maxn],mn[25][maxn];
void pre_RMQ()
{
	Bin[0]=1;for(int i=1;i<=23;i++)Bin[i]=Bin[i-1]*2;
	Log[1]=0;for(int i=2;i<=n; i++)Log[i]=Log[i/2]+1;
	
	for(int j=1;Bin[j]<=n;j++)
		for(int i=1;i+Bin[j]-1<=n;i++)
		{
			if(a[mn[j-1][i]]<a[mn[j-1][i+Bin[j-1]]])
				mn[j][i]=mn[j-1][i];
			else
				mn[j][i]=mn[j-1][i+Bin[j-1]];
		}
}
int RMQ(int l,int r)
{
	int k=Log[r-l+1];
	if(a[mn[k][l]]<a[mn[k][r-Bin[k]]])
		return mn[k][l];
	else
		return mn[k][r-Bin[k]+1];
}

int pr,prime[110000]; bool v[110000];
void get_prime()
{
	v[1]=true;
	for(int i=2;i<=100000;i++)
	{
		if(!v[i])prime[++pr]=i;
		else 
		{
			for(int j=1;j<=pr&&i*prime[j]<=100000;j++)
			{
				v[i*prime[j]]=true;
				if(i%prime[j]==0)continue;
			}
		}
	}
}


vector<int>vec;
int z,p[110],q[110];
void dfs(int k,int now)
{
	if(k==z+1)
	{
		vec.push_back(now);
		return ;
	}
	for(int i=0;i<=q[k];i++)
	{
		dfs(k+1,now);
		now*=p[k];
	}
}
void get_yue(int d)
{
	z=0;
	for(int i=1;prime[i]*prime[i]<=d;i++)
	{
		if(d%prime[i]==0)
		{
			z++;p[z]=prime[i];q[z]=0;
			while(d%prime[i]==0)
				q[z]++,d/=prime[i];
		}
	}
	if(d!=1)z++,p[z]=d,q[z]=1;
		
	dfs(1,1);
}


int cnt;
map<int,int>mp;
void solve(int x,int y)
{
//	printf("cos: %d %d\n",x,y);
	
	cnt++;	
	vec.clear();
	get_yue(y-x);
//	for(auto it:vec)printf("%d\n",it);
	
	for(int i=0;i<vec.size();i++)
	{
		int d=vec[i]-x;
		if(d<=0||d>K)continue;
		mp[d]++;
	}
}

int divi(int l,int r)
{
	if(l==r)return l;
	if(l>r)return 0;
	int p=RMQ(l,r);
	int x=divi(l,p-1);
	int y=divi(p+1,r);
	
	if(x&&a[p]!=a[x])solve(a[p],a[x]);
	if(y&&a[p]!=a[y])solve(a[p],a[y]);
	return p;
}

int main()
{
	get_prime();
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&K);
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]),mn[0][i]=i;
		pre_RMQ();
		
		cnt=0; mp.clear();
		divi(1,n);
		
		long long tot=0,sum=0;
		for(auto it:mp)
			if(it.second==cnt)tot++,sum+=it.first;
		
		if(cnt==0)
			tot=K,sum=(long long)K*(K+1)/2;
			
		printf("%lld %lld\n",tot,sum);
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4248kb

input:

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000

output:

3 8
0 0
100 5050

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 6240kb

input:

4
201 1000000000
1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...

output:

0 0
0 0
0 0
0 0

result:

ok 4 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 6420kb

input:

500
4 1000000000
8 14 24 18
4 1000000000
17 10 18 14
4 1000000000
6 17 19 19
4 1000000000
15 14 15 25
4 1000000000
16 16 5 25
4 1000000000
4 30 20 5
4 1000000000
11 4 23 9
4 1000000000
14 25 13 2
4 1000000000
18 18 1 15
4 1000000000
22 22 22 28
4 1000000000
15 17 17 10
4 1000000000
22 14 13 25
4 100...

output:

0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
...

result:

ok 500 lines

Test #4:

score: 0
Accepted
time: 3ms
memory: 10444kb

input:

1
50000 1000000000
230 286458 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 ...

output:

0 0

result:

ok single line: '0 0'

Test #5:

score: 0
Accepted
time: 6ms
memory: 11180kb

input:

1
50000 1000000000
12087 1196491 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 553146...

output:

0 0

result:

ok single line: '0 0'

Test #6:

score: 0
Accepted
time: 8ms
memory: 10796kb

input:

1
50000 1000000000
2138984 42249920 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 3581...

output:

0 0

result:

ok single line: '0 0'

Test #7:

score: -100
Wrong Answer
time: 12ms
memory: 6412kb

input:

500
39 1000000000
75 7 7 381 41 1197 177 177 41 109 109 16 1197 177 41 381 1605 381 381 7 177 177 177 177 177 177 177 177 7 7 143 143 143 143 143 653 143 823 7
61 1000000000
327 327 327 327 405153474 327 405153474 327 810306621 810306621 810306621 810306621 810306621 810306621 810306621 810306621 81...

output:

0 0
25 631568356
13 18925862
1 1
2 6878
0 0
1 1
2 10
1 1
1 110
0 0
1 36
11 4796
0 0
1 4
6 2209209
0 0
0 0
0 0
9 30770061
1000000000 500000000500000000
0 0
1000000000 500000000500000000
0 0
0 0
0 0
6 6615501
0 0
2 1035
0 0
7 1288
0 0
0 0
16 1617883221
2 10
0 0
0 0
15 102584
3 1100
1000000000 50000000...

result:

wrong answer 6th lines differ - expected: '1 2', found: '0 0'