QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#854444#9738. Make It Divisibleucup-team139#WA 4ms53572kbC++233.6kb2025-01-12 01:22:462025-01-12 01:22:48

Judging History

你现在查看的是最新测评结果

  • [2025-01-12 01:22:48]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:53572kb
  • [2025-01-12 01:22:46]
  • 提交

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)
    {
      vector<int> opz;
      for (long long i = 1; i * i <= gcd; i++)
      {
        if (gcd % i == 0)
        {
          opz.push_back(i);
          if (gcd / i != i)
            opz.push_back(gcd / i);
        }
      }

      for (auto i : opz)
      {
        if (i > b)
          sol.push_back(i - b);
      }
    }
    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: 11764kb

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: 28448kb

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: 11828kb

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: 3ms
memory: 53572kb

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: 3ms
memory: 27808kb

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: 3ms
memory: 29676kb

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
Wrong Answer
time: 4ms
memory: 24120kb

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
11 2194
2 6878
1 2
1 1
2 10
3 6873
1 110
0 0
1 36
13 19290
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
1...

result:

wrong answer 4th lines differ - expected: '1 1', found: '11 2194'