QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#801197 | #9738. Make It Divisible | Proaes | WA | 1ms | 3960kb | C++17 | 3.6kb | 2024-12-06 19:21:10 | 2024-12-06 19:21:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
template <typename T>
class SparseTable1 {
using VT = vector<T>;
using VVT = vector<VT>;
using func_type = function<T(const T &, const T &)>;
VVT ST;
static T default_func(const T &t1, const T &t2) { return __gcd(t1, t2); }
func_type op;
public:
SparseTable1(const vector<T> &v, func_type _func = default_func) {
op = _func;
ll len = v.size(), l1 = ceil(log2(len)) + 1;
ST.assign(len, VT(l1, 0));
for (ll i = 0; i < len; ++i) {
ST[i][0] = v[i];
}
for (ll j = 1; j < l1; ++j) {
ll pj = (1 << (j - 1));
for (ll i = 0; i + pj < len; ++i) {
ST[i][j] = op(ST[i][j - 1], ST[i + (1 << (j - 1))][j - 1]);
}
}
}
T query(ll l, ll r) {
ll lt = r - l + 1;
ll q = floor(log2(lt));
return op(ST[l][q], ST[r - (1 << q) + 1][q]);
}
};
template <typename T>
class SparseTable2 {
using VT = vector<T>;
using VVT = vector<VT>;
using func_type = function<T(const T &, const T &)>;
VVT ST;
static T default_func(const T &t1, const T &t2) { return min(t1, t2); }
func_type op;
public:
SparseTable2(const vector<T> &v, func_type _func = default_func) {
op = _func;
ll len = v.size(), l1 = ceil(log2(len)) + 1;
ST.assign(len, VT(l1, 0));
for (ll i = 0; i < len; ++i) {
ST[i][0] = v[i];
}
for (ll j = 1; j < l1; ++j) {
ll pj = (1 << (j - 1));
for (ll i = 0; i + pj < len; ++i) {
ST[i][j] = op(ST[i][j - 1], ST[i + (1 << (j - 1))][j - 1]);
}
}
}
T query(ll l, ll r) {
ll lt = r - l + 1;
ll q = floor(log2(lt));
return op(ST[l][q], ST[r - (1 << q) + 1][q]);
}
};
ll check(vector<ll> b){
ll n = b.size();
SparseTable1<ll> stg(b), stmin(b);
ll ok = 1;
for(ll i =0;i<n;i++){
ll p = i;
while(p<n){
ll l = p , r = n;
ll ng = stg.query(i,p);
while(l+1!=r){
ll m = l+r>>1;
if(stg.query(i,m) == ng){
l = m;
}else r = m;
}
p = l;
if(stg.query(i,p) != stmin.query(i,p)){
ok = 0;break;
}
p++;
if(p>=n) break;
if(stg.query(i,p)!=stmin.query(i,p)){
ok = 0;break;
}
}
if(ok == 0) break;
}
return ok;
}
void solve(){
ll n , k ;cin>>n>>k;
vector<ll> a(n);
for(ll&x:a) cin>>x;
ll mx = *max_element(a.begin(),a.end());
ll mi = *min_element(a.begin(),a.end());
if(mx == mi){
cout<<k<<" ";
cout<<(1 + k) * k /2<<endl;
return;
}
vector<ll> ck;
ll yd = 0;
for(ll i =0;i<n - 1;i++){
if(a[i] == a[i+1]) continue;
mx = max(a[i] ,a[i+1]);
mi = min(a[i] ,a[i+1]);
yd = mi;
ll d = mx - mi;
for(ll i = 1;i*i<=d;i++){
if(d % i == 0){
ck.push_back(i);
if(i*i!=d) ck.push_back(d/i);
}
}
break;
}
vector<ll> ans;
ll ans1= 0 ,ans2 = 0;
mi = *min_element(a.begin(),a.end());
for(ll x : ck){
ll g = 0;
x -= yd;
if(x <1 || x > k) continue;
ll d = x;
auto b = a;
for(ll i =0;i<n;i+=1) b[i] += d;
if(check(b)){
ans1 += 1;ans2 += x;
}
}
cout<<ans1<<" "<<ans2<<endl;
}
signed main(){
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(0);
ll t;cin>>t;while(t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
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: 1ms
memory: 3960kb
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:
2 4 3 8 2 4 3 18
result:
wrong answer 1st lines differ - expected: '0 0', found: '2 4'