QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#750540 | #9730. Elevator II | 552Hz# | WA | 3ms | 15476kb | C++17 | 2.2kb | 2024-11-15 14:53:49 | 2024-11-15 14:53:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<": "<<x<<endl
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll=long long;
using ull=unsigned long long;
const int N=200010;
ll a[N],n,lg[1000000];
ll k;
pair<ll,ll> st[22][N];
void init(){
for(int i=1;i<=n;i++){
st[0][i]={a[i],i};
}
for(int j=1;j<22;j++){
for(int i=1;i+(1<<j)-1<=n;i++){
st[j][i]=min(st[j-1][i],st[j-1][i+(1<<(j-1))]);
}
}
}
int query(int l,int r){
int len=lg[r-l+1];
return min(st[len][l],st[len][r-(1<<len)+1]).second;
}
bool flag;
ll divide(int l,int r,ll x){
if(l>r){
return 0;
}
if(l==r){
return a[l]+x;
}
int p=query(l,r);
ll l1=divide(l,p-1,x);
ll r1=divide(p+1,r,x);
ll w=__gcd(l1,r1);
w=__gcd(w,1ll*(a[p]+x));
if(w<(a[p]+x)){
flag=0;
}
return w;
}
bool check(ll x){
flag=1;
divide(1,n,x);
return flag;
}
void solve(){
cin>>n>>k;
ll minn=1e10;
for(int i=1;i<=n;i++){
cin>>a[i];
minn=min(minn,a[i]);
}
init();
ll g=0;
for(int i=1;i<=n;i++){
g=__gcd(g,1ll*(a[i]-minn));
}
if(g==0){
cout<<k<<" "<<((k)*(k+1))/2<<endl;
return;
}
ll cnt=0,sum=0;
for(ll i=1;i*i<=g;i++){
if(i*i==g){
if(i>minn&&(i-minn)<=k&&check(i-minn)){
cnt++;
sum+=i-minn;
}
continue;
}
if(g%i==0){
if(i>minn&&(i-minn)<=k&&check(i-minn)){
cnt++;
sum+=i-minn;
}
if(g/i>minn&&(g/i-minn)<=k&&check(g/i-minn)){
cnt++;
sum+=g/i-minn;
}
}
}
cout<<cnt<<" "<<sum<<endl;
}
signed main(){
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int t=1;
cin>>t;
for(int i=2;i<1000000;i++){
lg[i]=lg[i/2]+1;
}
while(t--){
solve();
}
}
/*
贡献法
正难则反
数小状压
关系连边
拆位
广义单调性
最长转最短
*/
详细
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 15476kb
input:
2 4 2 3 6 1 3 2 7 5 6 2 5 2 4 6 8
output:
0 0 0 0
result:
wrong answer Integer parameter [name=a_i] equals to 0, violates the range [1, 4] (test case 1)