QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#764888 | #9738. Make It Divisible | tjf4 | WA | 1ms | 3588kb | C++20 | 2.1kb | 2024-11-20 11:04:23 | 2024-11-20 11:04:24 |
Judging History
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 int 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) {
long long ans=k;
long long sum=(1ll+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());
long long mi=min(b[pd],b[pd-1]);
long long 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: 3588kb
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'