QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#340236 | #7881. Computational Complexity | JWRuixi | WA | 130ms | 47572kb | C++17 | 2.0kb | 2024-02-28 19:42:55 | 2024-02-28 19:42:56 |
Judging History
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 % P;
g[0] = Y % P;
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;
}
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!
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 123ms
memory: 47236kb
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: 129ms
memory: 47144kb
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: 130ms
memory: 47572kb
input:
2023 2023 10 2023 0 1 2 3 4 5 6 7 8 9
output:
0 0 1 1 2 2 3 3 4 4 5 5 6 7 7 7 8 9 9 10
result:
wrong answer 3rd numbers differ - expected: '0', found: '1'