QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#854441 | #9738. Make It Divisible | ucup-team139# | TL | 12ms | 48136kb | C++23 | 3.5kb | 2025-01-12 01:20:14 | 2025-01-12 01:20:22 |
Judging History
answer
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#include <climits>
#include <iomanip>
using namespace std;
constexpr int MAXN = 1 << 18, LOGN = 21;
pair<int, int> table[LOGN][MAXN]; // sparse table per il minimo
void build(int N, pair<int, int> *V)
{ //$\mathcal{O}(N\log{N})$
copy(V, V + N, table[0]);
for (int j = 1; j < LOGN; j++)
{
for (int i = 0; i + (1 << j) <= N; i++)
{
table[j][i] = min(table[j - 1][i],
table[j - 1][i + (1 << j) / 2]);
}
} // 0-based (indici di V da 0 a N-1)
}
pair<int, int> query(int l, int r)
{ //[l, r) ($\mathcal{O}(1)$)
int k = 31 - __builtin_clz(r - l);
return min(table[k][l], table[k][r - (1 << k)]);
}
int table2[LOGN][MAXN]; // sparse table per il minimo
void build2(int N, int *V)
{ //$\mathcal{O}(N\log{N})$
copy(V, V + N, table2[0]);
for (int j = 1; j < LOGN; j++)
{
for (int i = 0; i + (1 << j) <= N; i++)
{
table2[j][i] = __gcd(table2[j - 1][i],
table2[j - 1][i + (1 << j) / 2]);
}
} // 0-based (indici di V da 0 a N-1)
}
int query2(int l, int r)
{ //[l, r) ($\mathcal{O}(1)$)
int k = 31 - __builtin_clz(r - l);
return __gcd(table2[k][l], table2[k][r - (1 << k)]);
}
void solve([[maybe_unused]] int t)
{
long long n, k;
cin >> n >> k;
pair<int, int> v[n];
int v2[n - 1];
for (int i = 0; i < n; i++)
{
cin >> v[i].first;
v[i].second = i;
}
for (int i = 0; i < n - 1; i++)
{
v2[i] = abs(v[i + 1].first - v[i].first);
}
build(n, v);
build2(n - 1, v2);
bool ok = true;
vector<int> sol;
auto upd = [&](int b, int gcd) -> void
{
if (gcd == 0 || !ok)
return;
if (gcd <= b)
{
ok = false;
return;
}
if (sol.size() == 0)
{
for (int x = 1; b + x <= gcd; x++)
{
if (gcd % (b + x) == 0)
{
sol.push_back(x);
}
}
}
else
{
vector<int> succ;
for (auto x : sol)
{
if (gcd % (b + x) == 0)
{
succ.push_back(x);
}
}
if (succ.size() == 0)
ok = false;
else
sol = succ;
}
};
auto calc = [&](auto &calc, int l, int r) -> void
{
if (r - l <= 1)
return;
auto [mini, pos] = query(l, r);
int gcd = query2(l, r - 1);
upd(mini, gcd);
calc(calc, l, pos);
calc(calc, pos + 1, r);
};
calc(calc, 0, n);
if (!ok)
{
cout << "0 0\n";
}
else if (sol.size() == 0)
{
cout << k << " " << k * (k + 1) / 2ll << "\n";
}
else
{
long long ans = 0;
for (auto i : sol)
ans += i;
cout << sol.size() << " " << ans << "\n";
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n = 1;
cin >> n;
for (int i = 1; i <= n; i++)
solve(i);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11820kb
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: 28180kb
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: 0
Accepted
time: 2ms
memory: 11752kb
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:
ok 500 lines
Test #4:
score: 0
Accepted
time: 7ms
memory: 48136kb
input:
1 50000 1000000000 230 286458 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 ...
output:
0 0
result:
ok single line: '0 0'
Test #5:
score: 0
Accepted
time: 4ms
memory: 41756kb
input:
1 50000 1000000000 12087 1196491 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 553146...
output:
0 0
result:
ok single line: '0 0'
Test #6:
score: 0
Accepted
time: 12ms
memory: 32700kb
input:
1 50000 1000000000 2138984 42249920 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 3581...
output:
0 0
result:
ok single line: '0 0'
Test #7:
score: -100
Time Limit Exceeded
input:
500 39 1000000000 75 7 7 381 41 1197 177 177 41 109 109 16 1197 177 41 381 1605 381 381 7 177 177 177 177 177 177 177 177 7 7 143 143 143 143 143 653 143 823 7 61 1000000000 327 327 327 327 405153474 327 405153474 327 810306621 810306621 810306621 810306621 810306621 810306621 810306621 810306621 81...