QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751671 | #9738. Make It Divisible | sdnuwy# | WA | 2ms | 9780kb | C++20 | 3.2kb | 2024-11-15 20:05:44 | 2024-11-15 20:05:44 |
Judging History
answer
//Think twice,code once.
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define INF 0x3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define ff first
#define ss second
#define pii pair<int,int>
#define mem(i,n) memset(i,n,sizeof i)
#define dg(a) std::cout << #a << " = " << a << endl
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int N=5e4+10;
int st[N][20];
int pos[N][20];
int stgcd[N][20];
int a[N];
int lg2[N];
int b[N];
void build(int n) {
for (int i = 2; i <= n; i ++ ) lg2[i] = lg2[i >> 1] + 1;
for (int i = 1; i <= n; i ++ )
{
st[i][0] = a[i];
pos[i][0]=i;
}
for (int j = 1; (1 << j) <= n; j ++ ) {
for (int i = 1; i + (1 << j - 1) <= n; i ++ ) {
if(st[i][j-1]<st[i + (1 << j - 1)][j - 1])
{
pos[i][j]=pos[i][j-1];
}
else
{
pos[i][j]=pos[i + (1 << j - 1)][j - 1];
}
st[i][j] = min(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
}
}
}
void build_gcd(int n)
{
for (int i = 1; i <= n; i ++ )
{
stgcd[i][0]=b[i];
}
for (int j = 1; (1 << j) <= n; j ++ ) {
for (int i = 1; i + (1 << j - 1) <= n; i ++ ) {
stgcd[i][j] = gcd(stgcd[i][j - 1], stgcd[i + (1 << j - 1)][j - 1]);
}
}
}
int query_num(int l, int r) {
int s = lg2[r - l + 1];
return min(st[l][s], st[r - (1 << s) + 1][s]);
}
int query_pos(int l,int r)
{
int s=lg2[r-l+1];
if(st[l][s]<st[r - (1 << s) + 1][s])
{
return pos[l][s];
}
else
{
return pos[r - (1 << s) + 1][s];
}
}
int query_gcd(int l,int r)
{
int s = lg2[r - l + 1];
return gcd(stgcd[l][s], stgcd[r - (1 << s) + 1][s]);
}
bool check(int l,int r,int x)
{
if(l==r||l<r) return true;
bool res=true;
if(query_num(l,r)+x>query_gcd(l,r)) return false;
int idx=query_pos(l,r);
res&=check(l,idx-1,x);
res&=check(idx+1,r,x);
return res;
}
void solve()
{
int n,k;
cin >> n >> k;
int num=0;
int mn=inf;
for(int i=1;i<=n;i++)
{
cin >> a[i];
mn=min(mn,a[i]);
}
bool flag=1;
for(int i=2;i<=n;i++)
{
if(a[i]!=a[i-1]) flag=false;
}
if(flag)
{
cout << k << ' ' << k*(k+1)/2 << endl;
return;
}
build(n);
for(int i=2;i<=n;i++)
{
num=gcd(num,abs(a[i]-a[i-1]));
}
int ans1=0;
int ans2=0;
vector<int>c;
for(int i=1;i*i<=num;i++)
{
if(num%i==0)
{
c.push_back(i);
if(num/i!=i) c.push_back(num/i);
}
}
for(int y:c)
{
int x=y-mn;
if(x<=0) continue;
for(int i=1;i<=n;i++)
{
b[i]=a[i]+x;
}
build_gcd(n);
if(check(1,n,x))
{
ans1++;
ans2+=x;
}
}
cout << ans1 << ' ' << ans2 << endl;
}
int32_t main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int t = 1;
std::cin >> t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9652kb
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: -100
Wrong Answer
time: 2ms
memory: 9780kb
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 1 1 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '0 0', found: '1 1'