QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#864864#9738. Make It DivisiblelinxuanruiWA 1ms11876kbC++142.1kb2025-01-21 10:06:172025-01-21 10:06:17

Judging History

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

  • [2025-01-21 10:06:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:11876kb
  • [2025-01-21 10:06:17]
  • 提交

answer

#include<bits/stdc++.h>
//#define int long long
//#define gg(a,b) (a-1)/b+1

using namespace std;

const int N=2e5+5;

long long n,a[N],b[N],st[N][25],f[N],lg[N],k,w,w1,ansa,ansb,p[N],q[N];

void clean(){
	ansa=ansb=0;
}

void forst(){
	for(int i=1;i<=n;i++) st[i][0]=i;
	for(int j=1;j<=20;j++)
		for(int i=1;i+(1<<j-1)<=n;i++) st[i][j]=((b[st[i][j-1]]<=b[st[i+(1<<j-1)][j-1]])?st[i][j-1]:st[i+(1<<j-1)][j-1]);
	lg[0]=-1;
	for(int i=1;i<=n;i++) lg[i]=lg[i/2]+1;
}

inline int ask(int l,int r){
	int len=r-l+1;
	return ((b[st[l][lg[len]]]<=b[st[r-(1<<lg[len])+1][lg[len]]])?st[l][lg[len]]:st[r-(1<<lg[len])+1][lg[len]]);
}

inline int build(int l,int r){
	int x=ask(l,r);
	int ls=0,rs=0;
	if(l<x) ls=build(l,x-1);
	if(x<r) rs=build(x+1,r);
	p[x]=ls,q[x]=rs;
	return x;
}

inline void dp(int x,int l,int r,int www){
//	int x=ask(l,r);
//	cout<<l<<" "<<r<<" "<<x<<" "<<f[x]<<"\n";
	int ls=p[x],rs=q[x];
	f[x]=1;
	if(l<x) dp(ls,l,x-1,www),f[x]&=((b[ls]+www)%(b[x]+www)==0);
	if(x<r) dp(rs,x+1,r,www),f[x]&=((b[rs]+www)%(b[x]+www)==0);
	if(ls) f[x]&=f[ls];
	if(rs) f[x]&=f[rs];
	if(!p){
		if(ls&&b[x]!=b[ls]) w=b[ls]-b[x],w1=b[x];
		if(rs&&b[x]!=b[rs]) w=b[rs]-b[x],w1=b[x];
	}
}

void solve(){
	cin>>n>>k;
	bool p=1;
	for(int i=1;i<=n;i++) cin>>b[i],p&=(b[i]==b[1]);
	if(p){
		cout<<k<<" "<<k*(k+1)/2<<"\n";
		return;
	}
	forst();
	build(1,n);
	int rt=ask(1,n);
	dp(ask(1,n),1,n,0);
//	cout<<w<<"\n";
	for(int i=1;i*i<=w;i++){
		if(i*i==w){
			if(i-w1<=k&&i>w1){
				dp(ask(1,n),1,n,i-w1);
				if(f[rt]) ansa++,ansb+=i-w1;//,cout<<i-w1<<" ";
			}
 		}
 		else if(w%i==0){
 			if(i-w1<=k&&i>w1){
 				dp(ask(1,n),1,n,i-w1);
				if(f[rt]) ansa++,ansb+=i-w1;//,cout<<i-w1<<" ";
			 }
			if(w/i-w1<=k&&w/i>w1){
				dp(ask(1,n),1,n,w/i-w1);
				if(f[rt]) ansa++,ansb+=w/i-w1;//,cout<<w/i-w1<<" ";
			}
		 }
	}
//	cout<<"\n";
	cout<<ansa<<" "<<ansb<<"\n";
//	cout<<"\n\n";
}

signed main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--) solve(),clean();
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 11876kb

input:

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

output:

0 0
0 0
100 5050

result:

wrong answer 1st lines differ - expected: '3 8', found: '0 0'