QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#759340#9738. Make It Divisibletjf4WA 2ms6552kbC++202.1kb2024-11-18 01:17:302024-11-18 01:17:32

Judging History

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

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

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;
	}
	return 1;
	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: 100
Accepted
time: 1ms
memory: 5560kb

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: 5508kb

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: 1ms
memory: 5504kb

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: 2ms
memory: 6552kb

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: -100
Wrong Answer
time: 2ms
memory: 6548kb

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:

1 33467

result:

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