QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#852783 | #9738. Make It Divisible | ucup-team5234# | WA | 298ms | 12532kb | C++23 | 5.1kb | 2025-01-11 13:58:40 | 2025-01-11 13:58:44 |
Judging History
answer
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include "bits/stdc++.h"
using namespace std;
using ll = int;
#define rep(i,n) for(int i=0;i<n;i++)
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()
const ll INF = (1LL << 30);
using namespace __gnu_pbds;
// base: bafcf8
unsigned int bit_ceil(unsigned int n) {
unsigned int x = 1;
while(x < (unsigned int)(n)) x *= 2;
return x;
}
int countr_zero(unsigned int n) { return __builtin_ctz(n); }
constexpr int countr_zero_constexpr(unsigned int n) {
int x = 0;
while(!(n & (1 << x))) x++;
return x;
}
template<class S, S (*op)(S, S), S (*e)()> struct segtree {
public:
segtree() : segtree(0) {}
explicit segtree(int n) : segtree(vector<S>(n, e())) {}
explicit segtree(const vector<S>& v) : _n(int(v.size())) {
size = (int)bit_ceil((unsigned int)(_n));
log = countr_zero((unsigned int)size);
d = vector<S>(2 * size, e());
for(int i = 0; i < _n; i++) d[size + i] = v[i];
for(int i = size - 1; i >= 1; i--) { update(i); }
}
void set(int p, S x) {
// assert(0 <= p && p < _n);
p += size;
d[p] = x;
for(int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) const {
// assert(0 <= p && p < _n);
return d[p + size];
}
S prod(int l, int r) const {
// assert(0 <= l && l <= r && r <= _n);
S sml = e(), smr = e();
l += size;
r += size;
while(l < r) {
if(l & 1) sml = op(sml, d[l++]);
if(r & 1) smr = op(d[--r], smr);
l >>= 1;
r >>= 1;
}
return op(sml, smr);
}
S all_prod() const { return d[1]; }
template<class F> int max_right(int l, F f) {
// assert(0 <= l && l <= _n);
// assert(f(e()));
if(l == _n) return _n;
l += size;
S sm = e();
do {
while(l % 2 == 0) l >>= 1;
if(!f(op(sm, d[l]))) {
while(l < size) {
l = (2 * l);
if(f(op(sm, d[l]))) {
sm = op(sm, d[l]);
l++;
}
}
return l - size;
}
sm = op(sm, d[l]);
l++;
} while((l & -l) != l);
return _n;
} // faa03f
template<class F> int min_left(int r, F f) {
// assert(0 <= r && r <= _n);
// assert(f(e()));
if(r == 0) return 0;
r += size;
S sm = e();
do {
r--;
while(r > 1 && (r % 2)) r >>= 1;
if(!f(op(d[r], sm))) {
while(r < size) {
r = (2 * r + 1);
if(f(op(d[r], sm))) {
sm = op(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(d[r], sm);
} while((r & -r) != r);
return 0;
} // efa466
private:
int _n, size, log;
vector<S> d;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};
using P = pair<ll, int> ;
P e1() {
return {INF, -1};
}
P op1(P a, P b) {
return min(a, b);
}
ll e() {
return 0;
}
ll op(ll a, ll b) {
return __gcd(a, b);
}
vector<ll> divisor(ll n) {
vector<ll> v;
for(ll i = 1; i * i <= n; i ++) {
if(n % i == 0) {
if(i * i != n) v.pb(n/i);
v.pb(i);
}
}
return v;
}
void solve() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) {
cin >> a[i];
}
auto b = a;
sort(all(b));
ll g = 0;
rep(i, n - 1) g = __gcd(g, b[i + 1] - b[i]);
if(g == 0) {
long long K = k;
cout << K << " " << (K + 1) * K / 2 << endl;
return ;
}
vector<P> minbase(n);
rep(i, n) {
minbase[i] = {a[i], i};
}
segtree<P, op1, e1> segmin(minbase);
vector<ll> c(n - 1);
rep(i, n - 1) c[i] = abs(a[i + 1] - a[i]);
segtree<ll, op, e> seggcd(c);
gp_hash_table<ll, P> mpmin;
gp_hash_table<ll, ll> mpgcd;
unordered_set<ll> st;
// unordered_map<ll, P> mpmin;
// unordered_map<ll, ll> mpgcd;
auto dfs = [&](auto dfs, ll le, ll ri, ll x) -> bool {
if(le >= ri) return true;
ll idx = ri * n + le;
if(!st.count(idx)) {
mpmin[idx] = segmin.prod(le, ri);
mpgcd[idx] = seggcd.prod(le, ri - 1);
st.insert(idx);
}
ll G = mpgcd[idx];
if(G == 0) return true;
auto [M, Mid] = mpmin[idx];
if(G % (M + x) == 0) {
return (dfs(dfs, le, Mid, x) & dfs(dfs, Mid + 1, ri, x));
} else return false;
};
ll Min = b[0];
auto vec = divisor(g);
ll cnt = 0, ans = 0;
for(ll e : vec) {
if(e > Min) {
if(e - Min > k) continue;
if(dfs(dfs, 0, n, e - Min)) {
ans += e - Min;
cnt ++;
}
}
}
cout << cnt << " " << ans << endl;
}
int main(){
int t; cin >> t;
rep(i, t) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3472kb
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: 3476kb
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: 3472kb
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: 10ms
memory: 5676kb
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: 10ms
memory: 5676kb
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: 11ms
memory: 5740kb
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: 0
Accepted
time: 12ms
memory: 3732kb
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...
output:
0 0 25 631568356 13 18925862 1 1 2 6878 1 2 1 1 2 10 1 1 1 110 0 0 1 36 11 4796 1 29 1 4 6 2209209 0 0 3 8 1 2 9 30770061 1000000000 500000000500000000 1 3 1000000000 500000000500000000 0 0 1 5 1 1 6 6615501 3 8233825 2 1035 2 4 7 1288 0 0 1 3 16 1617883221 2 10 0 0 1 5739 15 102584 3 1100 100000000...
result:
ok 500 lines
Test #8:
score: 0
Accepted
time: 9ms
memory: 3964kb
input:
50 794 1000000000 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 ...
output:
4 13399 1 488 0 0 1 1 2 764 1 3762 2 3 1 4 3 704189325 1 1 7 226705168 7 2992 1 10 2 14 0 0 2 4136 1 1 5 1503264540 1 6 1 9 2 178 12 1965492 3 8622003 1 1 1 10 0 0 0 0 1 316605749 1 4 2 8 1 22 2 1452 0 0 1 47 1 1 3 11 7 709953544 20 10709552 3 8 1 3 19 84763135 2 1256 3 1268 29 1652299260 1 1 3 1124...
result:
ok 50 lines
Test #9:
score: 0
Accepted
time: 11ms
memory: 4928kb
input:
5 8181 1000000000 846711550 846711550 846711550 846711550 31870 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 31870 338703742 338703742 190 14224510 14224510 6526 6526 190 190 190 10 190 10 21214 21214 154 154 8578 10 190 10 10 82 3862 ...
output:
2 10 1 8 26 3610753 1 3 2 4
result:
ok 5 lines
Test #10:
score: 0
Accepted
time: 74ms
memory: 12532kb
input:
1 50000 1000000000 8376 1656 5016 20136 5016 1656 1656 1656 1656 1656 1656 1656 1656 1656 1656 16776 8376 50376 251976 1656 1656 10056 1656 1656 1656 1656 1656 1656 1656 1656 1656 1656 1656 5016 1656 3336 3336 3336 3336 3336 83976 16776 16776 16776 1656 536 1096 2216 1096 1096 67176 33576 5576 1096 ...
output:
1 24
result:
ok single line: '1 24'
Test #11:
score: 0
Accepted
time: 298ms
memory: 10684kb
input:
1 50000 1000000000 91892194 394 137838094 394 137838094 137838094 394 183783994 394 183783994 183783994 183783994 183783994 394 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 394 137838094 137838094 137838094 394 91892194...
output:
468 209787236
result:
ok single line: '468 209787236'
Test #12:
score: -100
Wrong Answer
time: 53ms
memory: 3508kb
input:
500 100 1000000000 776155459 776155459 776155459 776155459 41021059 776155459 41021059 776155459 776155459 41021059 41021059 776155459 776155459 41021059 776155459 41021059 776155459 776155459 41021059 41021059 776155459 776155459 776155459 41021059 41021059 41021059 41021059 41021059 776155459 7761...
output:
17 1831175377 2 609757842 3 743304987 25 2121624176 3 790868079 5 1008821895 7 1202438586 151 -911954368 9 1359636987 84 -1250294845 3 640906041 2 612154014 7 1176943151 4 813243996 3 707197023 3 683983701 2 602690182 21 1974972192 12 1549491756 35 -1903534630 3 794002920 3 764129706 3 748141920 14 ...
result:
wrong answer 8th lines differ - expected: '151 3383012928', found: '151 -911954368'