QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#748946 | #9738. Make It Divisible | kans2298 | WA | 107ms | 5844kb | C++17 | 3.0kb | 2024-11-14 22:06:25 | 2024-11-14 22:06:27 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<set>
#include<algorithm>
#include<random>
#include<numeric>
#include<cmath>
#define N 50000
#define LIM 40000
using namespace std;
int b[N+5];
struct node
{
int pos,v;
};
node c[N+5];
int k;
void query_k(int a,int b,set<int> &f)
{
if (a<b) swap(a,b);
for (int x=1;x<=min(k,LIM);++x)
if ((a+x)%(b+x)==0) f.insert(x);
// for (int y=2;y<=LIM;++y)
// {
// long long t=a-(long long)(y)*b,t2=t/(y-1);
// if (t%(y-1)==0 && t2>=1 && t2<=k) f.insert(t2);
// }
}
int st[N+5][17];
int query(int l,int r)
{
int x=floor(log2(r-l+1));
return gcd(st[l][x],st[r-(1<<x)+1][x]);
}
int main()
{
int t,ti;
//freopen("input.in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>t;
for (ti=1;ti<=t;++ti)
{
int n,i,j;
cin>>n>>k;
set<int> nn;
for (i=1;i<=n;++i)
{
cin>>b[i];
c[i]={i,b[i]};
nn.insert(b[i]);
}
sort(c+1,c+n+1,[](const node &a,const node &b) -> bool {
return a.v<b.v;
});
if (nn.size()==1)
{
cout<<k<<" "<<((long long)(k+1))*(k)/2<<"\n";
continue;
}
set<int> kk,k2,res;
random_device rd;
mt19937 gen(rd());
vector<int> unx;
for (auto elm:nn)
unx.push_back(elm);
uniform_int_distribution<> dist1(0,unx.size()-2);
for (i=1;i<=3;++i)
{
int x=dist1(gen);
kk.clear();
query_k(unx[x],unx[x+1],kk);
// cout<<b[x]<<" "<<b[x+1]<<"\n";
if (i==1) res=kk;
else
{
k2=res;
res.clear();
set_intersection(kk.begin(),kk.end(),k2.begin(),k2.end(),inserter(res,res.begin()));
}
}
kk=res;
// cout<<"k=";
// for (auto x:kk)
// {
// cout<<x<<" ";
// }
// cout<<"\n";
vector<int> ans;
for (auto x:kk)
{
bool okay=true;
for (i=1;i<=n;++i)
st[i][0]=b[i]+x;
for (j=1;j<=16;++j)
for (i=1;i<=n;++i)
st[i][j]=gcd(st[i][j-1],st[min(i+(1<<(j-1)),n)][j-1]);
set<int> pp;
pp.insert(0);
pp.insert(n+1);
for (i=1;i<=n;++i)
{
set<int>::iterator it=pp.upper_bound(c[i].pos);
int l,r;
r=*it;
l=*prev(it);
l=l+1,r=r-1;
if (query(l,r)!=c[i].v+x)
{
okay=false;
break;
}
pp.insert(c[i].pos);
}
if (okay) ans.push_back(x);
}
cout<<ans.size()<<" ";
long long sum=0;
for (auto elm:ans)
sum+=elm;
cout<<sum<<"\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3644kb
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: 3660kb
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: -100
Wrong Answer
time: 107ms
memory: 5844kb
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:
wrong answer 178th lines differ - expected: '1 2', found: '0 0'