QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#340237#7881. Computational ComplexityJWRuixiWA 111ms47256kbC++172.0kb2024-02-28 19:43:562024-02-28 19:43:56

Judging History

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

  • [2024-02-28 19:43:56]
  • 评测
  • 测评结果:WA
  • 用时:111ms
  • 内存:47256kb
  • [2024-02-28 19:43:56]
  • 提交

answer

#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
using namespace std;

using vi = vector<int>;

constexpr int S = 1 << 4;
constexpr int N = 4e5 + 9;
constexpr LL M = 1e15 + 7;
int T, X, Y;
LL P;

unordered_map<LL, LL> f, g;

int t;
LL a[N];

int main () {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> X >> Y >> T >> P;
  f[0] = X;
  g[0] = Y;
  L (i, 1, S) {
    f[i] = max((LL)i, g[i / 2] + g[i / 3] + g[i / 5] + g[i / 7]) % P;
    g[i] = max((LL)i, f[i / 2] + f[i / 3] + f[i / 4] + f[i / 5]) % P;
  }
  L (i, 0, S) {
    f[i] %= P;
    g[i] %= P;
  }
  R (i, N - 1, 1) {
    f[i] = (f[i] - f[i - 1] + P) % P;
    g[i] = (g[i] - g[i - 1] + P) % P;
  }
  L (o, 1, 13) {
    for (LL i = 1; i < M; i *= 2) {
      LL x = o * i;
      for (LL j = 1; x * j < M; j *= 3) {
        LL y = x * j;
        for (LL k = 1; y * k < M; k *= 5) {
          LL z = y * k;
          for (LL l = 1; z * l < M; l *= 7) {
            LL v = z * l;
            if (v > S) {
              a[++t] = v;
            }
          }
        }
      }
    }
  }
  sort(a + 1, a + t + 1);
  t = unique(a + 1, a + t + 1) - a - 1;
  L (i, 1, t) {
    LL x = a[i];
    f[x] = (x % 2 == 0 ? g[x / 2] : 0) + (x % 3 == 0 ? g[x / 3] : 0) + (x % 5 == 0 ? g[x / 5] : 0) + (x % 7 == 0 ? g[x / 7] : 0);
    g[x] = (x % 2 == 0 ? f[x / 2] : 0) + (x % 3 == 0 ? f[x / 3] : 0) + (x % 4 == 0 ? f[x / 4] : 0) + (x % 5 == 0 ? f[x / 5] : 0);
    f[x] %= P;
    g[x] %= P;
  }
  L (i, 1, S) {
    (f[i] += f[i - 1]) %= P;
    (g[i] += g[i - 1]) %= P;
  }
  a[0] = S;
  L (i, 1, t) {
    (f[a[i]] += f[a[i - 1]]) %= P;
    (g[a[i]] += g[a[i - 1]]) %= P;
  }
  while (T--) {
    LL v;
    cin >> v;
    if (v <= S) {
      cout << f[v] << ' ' << g[v] << '\n';
    } else {
      int p = upper_bound(a + 1, a + t + 1, v) - a - 1;
      cout << f[a[p]] << ' ' << g[a[p]] << '\n';
    } 
  }
}
// I love WHQ!

详细

Test #1:

score: 100
Accepted
time: 93ms
memory: 47256kb

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
784112 893714
1894550 1905470
12057866 12979424
71481494756 48626708512
28127864908 7251681354

result:

ok 20 numbers

Test #2:

score: 0
Accepted
time: 111ms
memory: 47180kb

input:

0 0 10 100000000000
0
1
2
3
4
10
20
30
40
100

output:

0 0
1 1
2 2
3 3
4 4
11 12
25 26
41 41
55 58
162 172

result:

ok 20 numbers

Test #3:

score: -100
Wrong Answer
time: 110ms
memory: 47104kb

input:

2023 2023 10 2023
0
1
2
3
4
5
6
7
8
9

output:

0 0
0 0
0 0
0 0
0 0
0 5
0 6
7 7
8 8
9 9

result:

wrong answer 12th numbers differ - expected: '0', found: '5'