QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#750491 | #9738. Make It Divisible | Susie_Rain# | RE | 0ms | 3852kb | C++20 | 2.8kb | 2024-11-15 14:43:56 | 2024-11-15 14:43:57 |
Judging History
answer
// _____ _ _____ _____ _____ _ __ __
// | ___| | | | _ \ | ____| | ___| | | \ \ / /
// | |__ | | | |_| | | |__ | |__ | | \ \/ /
// | __| | | | _ / | __| | __| | | \ /
// | | | | | | \ \ | |___ | | | |___ / /
// |_| |_| |_| \_\ |_____| |_| |_____| /_/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define lowbit(i) ((i) & -(i))
#define ull unsigned long long
// #define int long long
#define i64 long long
#define endl '\n'
using namespace std;
const int mod = 998244353;
const int N = 2e5 + 10;
void solve()
{
int n, k;
cin >> n >> k;
vector<int> lg(n + 1), a(n + 1), b(n + 1);
vector<pair<int, int>> c(n + 1);
vector<array<int, 3>> d;
lg[1] = 0;
for (int i = 2; i <= n; i++)
lg[i] = lg[i >> 1] + 1;
vector<vector<int>> f(n + 1, vector<int>(lg[n] + 1));
for (int i = 1; i <= n; i++)
{
cin >> a[i];
c[i] = {a[i], i};
f[i][0] = abs(a[i] - a[i - 1]);
}
for (int j = 1; j <= lg[n]; j++)
for (int i = 1; i <= n - (1 << j) + 1; i++)
f[i][j] = __gcd(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
auto ask = [&](int x, int y)
{
if (x > y)
return 0;
int l = lg[y - x + 1];
return __gcd(f[x][l], f[y - (1 << l) + 1][l]);
};
sort(c.begin() + 1, c.end());
set<int> st;
st.insert(0), st.insert(n + 1);
for (int i = 1; i <= n; i++)
{
auto it = st.lower_bound(c[i].second);
int r = *it;
int l = *--it;
d.push_back({l + 1, ask(l + 2, r - 1), c[i].first});
st.insert(c[i].second);
}
int res = -1, re;
for (int i = 2; i <= n; i++)
{
if (a[i] != a[i - 1])
{
res = abs(a[i] - a[i - 1]);
re = min(a[i], a[i - 1]);
break;
}
}
if (res == -1)
{
cout << k << ' ' << (i64)k * (k + 1) / 2 << endl;
return;
}
i64 ans = 0;
int cnt = 0;
auto check = [&](int x)
{
for (auto [l, g, y] : d)
{
if (__gcd(g, a[l] + x) % (y + x))
{
return;
}
}
ans += x, cnt++;
return;
};
for (int i = 1; i * i <= res; i++)
{
if (res % i)
continue;
if (i - re >= 1)
{
check(i - re);
}
if (res / i != i)
{
if (res / i - re <= k)
{
check(res / i - re);
}
}
}
cout << cnt << ' ' << ans << endl;
return;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int tt = 1;
cin >> tt;
while (tt--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
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: 0ms
memory: 3852kb
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
Runtime Error
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...