QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#759341#9738. Make It Divisibletjf4WA 1ms5924kbC++202.1kb2024-11-18 01:17:592024-11-18 01:17:59

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-18 01:17:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5924kb
  • [2024-11-18 01:17:59]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<char> vc;
const int inf=0x3f;
const int N=1e5+10;
ll n,k,b[N],l[N],r[N],q[N],lg[N];
int st[N][22];
void init() {
	for(int i=1;i<=n;i++) st[i][0]=q[i];
	for(int j=1;j<16;j++) {
		int x=1<<(j-1);
		for(int i=1;i+x<=n;i++) {
			st[i][j]=__gcd(st[i][j-1],st[i+x][j-1]);
		}
	}
}
int qry(int l,int r) {
	int s=lg[r-l+1],x=1<<s;
	return __gcd(st[l][s],st[r-x+1][s]);
}
bool check(ll mid) {
	for(int i=1;i<=n;i++) q[i]=b[i]+mid;
	for(int i=2;i<=n;i++) {
		if(q[i]%q[i-1]==0) continue;
		if(q[i-1]%q[i]==0) continue;
		return 0;
	}
	ll mi=q[1];
	for(int i=1;i<=n;i++) {
		mi=min(mi,q[i]);
		if(q[i]%mi) return 0;
	}
	reverse(q+1,q+n+1);
	mi=q[1];
	for(int i=1;i<=n;i++) {
		mi=min(mi,q[i]);
		if(q[i]%mi) return 0;
	}
	init();
	for(int i=1;i<=n;i++) {
		int lf=l[i]+1;
		int rf=r[i]-1;
		if(qry(lf,rf)!=q[i]) return 0;
	}
	return 1;
}
int main() {
	IOS
	int T;
	cin>>T;
	while(T--) {
		cin>>n>>k;
		for(int i=2;i<=n;i++) lg[i]=lg[i>>1]+1;
		for(int i=1;i<=n;i++) cin>>b[i];
		for(int i=1;i<=n;i++) {
			l[i]=i-1;
			while(l[i]>0&&b[l[i]]>=b[i]) l[i]=l[l[i]];
		}
		for(int i=n;i>=1;i--) {
			r[i]=i+1;
			while(r[i]<=n&&b[r[i]]>=b[i]) r[i]=r[r[i]];
		}
		ll pd=-1;
		for(int i=2;i<=n;i++) {
			if(b[i]!=b[i-1]) {
				if(pd<0) pd=i;
				else if(b[pd]-b[pd-1]>b[i]-b[i-1]) pd=i;
			}
		}
		if(pd<0) {
			ll ans=k;
			ll sum=(1+k)*k/2;
			cout<<ans<<' '<<sum<<'\n';
			continue; 
		}
		ll w=abs(b[pd]-b[pd-1]);
		vi g;
		for(ll i=1;i*i<=w;i++) {
			if(w%i) continue;
			g.push_back(i);
			if(i*i!=w) g.push_back(w/i);
		}
		sort(g.begin(),g.end());
		ll mi=min(b[pd],b[pd-1]);
		ll ans=0,sum=0;
		for(auto v:g) {
			ll x=v-mi;
			if(!(x>=1&&x<=k)) continue;
			if(check(x)) {
				ans++;
				sum+=x;
			}
		}
		cout<<ans<<' '<<sum<<'\n';
	}
    return 0;
}

詳細信息

Test #1:

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

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'