QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#866109#9738. Make It Divisibleucup-team3646#WA 1ms3712kbC++203.1kb2025-01-22 11:58:412025-01-22 11:58:48

Judging History

This is the latest submission verdict.

  • [2025-01-22 11:58:48]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3712kb
  • [2025-01-22 11:58:41]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define rep2(i, l, r) for(ll i = (l); i < (r); ++i)

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

#define all(A) A.begin(), A.end()
#define elif else if
using pii = pair<ll, ll>;

bool chmin(auto &a, auto b) {return a > b ? a = b, 1 : 0;}
bool chmax(auto &a, auto b) {return a < b ? a = b, 1 : 0;}

struct IOS {
  IOS() {
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
} iosetup;


template<class T>
void print(vector<T> a) {
  for(auto x : a) cout << x << ' ';
  cout << endl;
}

void print(auto x) {
  cout << x << endl;
}

template<class Head, class... Tail>
void print(Head &&head, Tail &&...tail) {
  cout << head << ' ';
  print(forward<Tail>(tail)...);
}

template<class S, S (*op) (S, S), S (*e)()>
struct segtree {
  int sz, N;
  vector<S> d;

  segtree() = default;
  segtree(int n) : segtree(vector<S>(n, e())) {}
  segtree(const vector<S> &v) {
    sz = 1;
    N = v.size();
    while(sz < N) sz <<= 1;
    d.assign(2 * sz, e());
    rep(i, N) d[i+sz] = v[i];
    for(int k = sz - 1; k > 0; k--) d[k] = op(d[2*k], d[2*k+1]);
  }

  void set(int k, S x) {
    k += sz;
    d[k] = x;
    while(k >>= 1) d[k] = op(d[2*k], d[2*k+1]);
  }

  S prod(int l, int r) {
    S sml = e(), smr = e();
    for(l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
      if(l&1) sml = op(sml, d[l++]);
      if(r & 1) smr = op(d[--r], smr);
    }
    return op(sml, smr);
  }

  S get(int k) {return d[k+sz];}

};

using S=pair<int,int>;
S op(S a,S b){return min(a,b);}
S e(){return {1<<30,1<<30};}

void solve(){
  int n;ll k;
  cin>>n>>k;
  vll a(n);
  rep(i,n)cin>>a[i];
  {
    ll mn=1<<30,mx=-1;
    for(auto x:a){
      mn=min(mn,x);
      mx=max(mx,x);
    }
    if(mn==mx){
      cout<<k*(k+1)/2<<'\n';
      return;
    }
  }
  vector<S>init(n);
  rep(i,n)init[i]={a[i],i};
  segtree<S,op,e>seg(init);
  vector<array<ll,2>>cand;
  auto dfs=[&](auto dfs,int l,int r)->int{
    if(l>=r)return -1;
    int mid=seg.prod(l,r).second;
    {
      int val=dfs(dfs,l,mid);
      if(val!=-1&&a[mid]!=a[val]){
        cand.push_back({a[mid],a[val]});
      }
    }
    {
      int val=dfs(dfs,mid+1,r);
      if(val!=-1&&a[mid]!=a[val]){
        cand.push_back({a[mid],a[val]});
      }
    }
    return mid;
  };


  dfs(dfs,0,n);
  assert(cand.size()>0);

  vll ans;
  {
    auto [a,b]=cand[0];
    ll d=b-a;
    ll i=1;
    vll div;
    while(i*i<=d){
      if(d%i==0){
        div.push_back(i);
        if(i*i!=d){
          div.push_back(d/i);
        }
      }
      i++;
    }
    for(auto y:div){
      ll x=y-a;
      if(1<=x&&x<=k)ans.push_back(x);
    }
  }
  for(auto [a,b]:cand){
    assert(a<b);
    vll nans;
    for(auto x:ans){
      if((b+x)%(a+x)==0)nans.push_back(x);
    }
    ans=nans;
  }
  ll sm=0;
  for(auto x:ans)sm+=x;
  cout<<ans.size()<<" "<<sm<<'\n';
}

int main(){
  int T;
  cin>>T;
  while(T--)solve();
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3712kb

input:

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000

output:

3 8
0 0
5050

result:

wrong answer 3rd lines differ - expected: '100 5050', found: '5050'