QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#288501#7881. Computational ComplexityckisekiWA 28ms53080kbC++204.5kb2023-12-22 19:29:132023-12-22 19:29:14

Judging History

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

  • [2023-12-22 19:29:14]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:53080kb
  • [2023-12-22 19:29:13]
  • 提交

answer

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

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#include <experimental/iterator>
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr << (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

using lld = int64_t;

pair<lld,lld> dpF[60][40][30][20];
pair<lld,lld> dpG[60][40][30][20];

lld prod[60][40][30][20];
const lld INF = 1e16;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  lld f0, g0, T;
  lld M;
  cin >> f0 >> g0 >> T >> M;

  const auto madd = [&](lld a, lld b) {
    return a + b >= M ? a + b - M : a + b;
  };
  const auto add = [&](pair<lld,lld> &x, pair<lld,lld> v) {
    x.first = madd(x.first, v.first);
    x.second = madd(x.second, v.second);
  };
  const auto msub = [&](pair<lld,lld> X, pair<lld,lld> Y) {
    auto [a, b] = X;
    auto [c, d] = Y;
    a = (a - c < 0 ? a - c + M : a - c);
    b = (b - d < 0 ? b - d + M : b - d);
    return pair(a, b);
  };

  const int maxn = 100;
  vector<lld> f(maxn), g(maxn);
  f[0] = f0;
  g[0] = g0;

  for (lld n = 1; n < maxn; n++) {
    f[n] = max(n, g[n / 2] + g[n / 3] + g[n / 5] + g[n / 7]);
    g[n] = max(n, f[n / 2] + f[n / 3] + f[n / 4] + f[n / 5]);
  }

  dpF[0][0][0][0] = pair(1, 0);
  dpG[0][0][0][0] = pair(0, 1);
  prod[0][0][0][0] = 1;

  vector<pair<lld, pair<lld,lld>>> preF, preG;

  for (int a = 0; a < 51; a++) {
    for (int b = 0; b < 33; b++) {
      for (int c = 0; c < 23; c++) {
        for (int d = 0; d < 19; d++) {

          prod[a][b][c][d] = min(prod[a][b][c][d], INF);
          prod[a + 1][b][c][d] = prod[a][b][c][d] * 2;
          prod[a][b + 1][c][d] = prod[a][b][c][d] * 3;
          prod[a][b][c + 1][d] = prod[a][b][c][d] * 5;
          prod[a][b][c][d + 1] = prod[a][b][c][d] * 7;

          if (prod[a][b][c][d] < INF) {
            preF.emplace_back(prod[a][b][c][d], dpF[a][b][c][d]);
            preG.emplace_back(prod[a][b][c][d], dpG[a][b][c][d]);
          }

          add(dpG[a + 1][b][c][d], dpF[a][b][c][d]);
          add(dpG[a][b + 1][c][d], dpF[a][b][c][d]);
          add(dpG[a][b][c + 1][d], dpF[a][b][c][d]);
          add(dpG[a][b][c][d + 1], dpF[a][b][c][d]);


          add(dpF[a + 1][b][c][d], dpG[a][b][c][d]);
          add(dpF[a][b + 1][c][d], dpG[a][b][c][d]);
          add(dpF[a][b][c + 1][d], dpG[a][b][c][d]);
          add(dpF[a + 2][b][c][d], dpG[a][b][c][d]);
        }
      }
    }
  }

  ranges::sort(preF);
  ranges::sort(preG);

  vector<pair<lld,lld>> pF(preF.size() + 1);
  vector<pair<lld,lld>> pG(preG.size() + 1);
  for (size_t i = 0; i < preF.size(); i++) {
    pF[i + 1] = pF[i];
    add(pF[i + 1], preF[i].second);
  }
  for (size_t i = 0; i < preG.size(); i++) {
    pG[i + 1] = pG[i];
    add(pG[i + 1], preG[i].second);
  }

  const auto query = [&](auto &pre, auto &p, lld l, lld r) {
    pair<lld,lld> res(0, 0);
    for (auto [f, S] : pre)
      if (l < f && f <= r)
        add(res, S);
    return res;
    // auto L = lower_bound(all(pre), pair(l, pair<lld,lld>(0, 0))) - pre.begin();
    // auto R = upper_bound(all(pre), pair(r, pair<lld,lld>(0, 0))) - pre.begin();
    // return msub(p[R], p[L]);
  };

  while (T--) {
    int64_t m;
    cin >> m;

    if (m < maxn) {
      cout << f[m] % M << ' ' << g[m] % M << '\n';
      continue;
    }

    lld ansF = 0, ansG = 0;

    for (int j = 9; j <= 56; j++) {

      lld r = m / j, l = m / (j + 1);

      auto coef = query(preF, pF, l, r);

      for (int k : {2, 3, 5, 7}) {
        if (j / k <= 8) {
          ansF += g[j / k] * coef.second;
        }
      }
      for (int k : {2, 3, 4, 5}) {
        if (j / k <= 8) {
          ansF += f[j / k] * coef.first;
        }
      }
    }

    for (int j = 9; j <= 56; j++) {

      lld r = m / j, l = m / (j + 1);

      auto coef = query(preG, pG, l, r);
      for (int k : {2, 3, 5, 7}) {
        if (j / k <= 8) {
          ansG += g[j / k] * coef.second;
        }
      }
      for (int k : {2, 3, 4, 5}) {
        if (j / k <= 8) {
          ansG += f[j / k] * coef.first;
        }
      }
    }

    cout << ansF << ' ' << ansG << '\n';

    // for (int j = 0; j < 8; j++) {
    //   int64_t l = m / (j + 1), r = m / j; // TODO
    // }
  }

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 28ms
memory: 53080kb

input:

1958 920 10 100000000000
0
1
2
3
10
100
200
1000
19580920
20232023

output:

1958 920
3680 7832
10592 9554
17504 11276
50294 64826
893714 784112
1905470 1894550
12891244 12013776
1640883225902 1564128649546
1697975630344 1619605267908

result:

wrong answer 11th numbers differ - expected: '784112', found: '893714'