QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#329444#7881. Computational ComplexityYansuan_HClWA 263ms16628kbC++143.2kb2024-02-16 18:49:572024-02-16 18:49:59

Judging History

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

  • [2024-02-16 18:49:59]
  • 评测
  • 测评结果:WA
  • 用时:263ms
  • 内存:16628kb
  • [2024-02-16 18:49:57]
  • 提交

answer

#include <bits/stdc++.h>
#define ms(x, v) memset(x, v, sizeof(x))
#define il __attribute__((always_inline)) static
#define U(i,l,r) for(int i(l),END##i(r);i<=END##i;++i)
#define D(i,r,l) for(int i(r),END##i(l);i>=END##i;--i)
using namespace std;
using ll = long long;

#define IC isdigit(c)
#define GC c=getchar()
void rd(auto &x) { x = 0; char GC; bool f = 0;
	for (; !IC; GC) f |= c == '-';
	for (; IC; GC) x = x * 10 + c - 48;
	if (f) x = -x;
}
void rd(auto &x, auto &...y) { rd(x); rd(y...); }
#define meow(...) fprintf(stderr, __VA_ARGS__)
#define Assert(e) if (!(e)) { meow("AF@%d\n", __LINE__); exit(__LINE__); }

const ll LIM = 1e15;
ll f[41], g[41], P;

int main() {
	// freopen("arrebol.in", "r", stdin);
	// freopen("arrebol.out", "w", stdout);

	int T;
	rd(f[0], g[0], T, P);
	bool fF = 0, fG = 0;
	U (i, 1, 40) {
		f[i] = g[i / 2] + g[i / 3] + g[i / 5] + g[i / 7];
		g[i] = f[i / 2] + f[i / 3] + f[i / 4] + f[i / 5];
		if (!fF) {
			if (f[i] > i) fF = 1;
			f[i] = max(f[i], ll(i));
		} else f[i] %= P;
		if (!fG) {
			if (g[i] > i) fG = 1;
			g[i] = max(g[i], ll(i));
		} else g[i] %= P;
	}
	U (i, 1, 40) f[i] %= P, g[i] %= P;

	set<pair<ll, int>> que; vector<pair<ll, ll>> dF, dG;
	dF.emplace_back(0, f[0]);
	dG.emplace_back(0, g[0]);
	U (i, 1, 40)
		dF.emplace_back(i, (f[i] - f[i - 1] + P) % P),
		dG.emplace_back(i, (g[i] - g[i - 1] + P) % P);
	auto acc = [&](vector<pair<ll, ll>> &v, ll p) -> ll {
		auto it = lower_bound(v.begin(), v.end(), make_pair(p, -1ll));
		if (it == v.end() || it->first != p)
			return 0;
		return it->second;
	};
	U (i, 1, 40) que.emplace(i, 0), que.emplace(i, 1);
	while (que.size()) {
		auto [u, t] = *que.begin(); que.erase(que.begin());
		if (t == 0) {
			if (2 * u <= LIM) que.emplace(2 * u, 1);
			if (3 * u <= LIM) que.emplace(3 * u, 1);
			if (5 * u <= LIM) que.emplace(5 * u, 1);
			if (7 * u <= LIM) que.emplace(7 * u, 1);
		} else {
			if (2 * u <= LIM) que.emplace(2 * u, 0);
			if (3 * u <= LIM) que.emplace(3 * u, 0);
			if (4 * u <= LIM) que.emplace(4 * u, 0);
			if (5 * u <= LIM) que.emplace(5 * u, 0);
		}
		if (u <= 40) continue;
		if (t == 0) {
			ll res = 0;
			if (!(u % 2)) res += acc(dG, u / 2);
			if (!(u % 3)) res += acc(dG, u / 3);
			if (!(u % 5)) res += acc(dG, u / 5);
			if (!(u % 7)) res += acc(dG, u / 7);
			dF.emplace_back(u, res % P);
		} else {
			ll res = 0;
			if (!(u % 2)) res += acc(dF, u / 2);
			if (!(u % 3)) res += acc(dF, u / 3);
			if (!(u % 4)) res += acc(dF, u / 4);
			if (!(u % 5)) res += acc(dF, u / 5);
			dG.emplace_back(u, res % P);
		}
	}
	clog << fF << ' ' << fG << endl;

	U (i, 1, dF.size() - 1) {
		assert(dF[i].first > dF[i - 1].first);
		(dF[i].second += dF[i - 1].second) %= P;
	}
	U (i, 1, dG.size() - 1) {
		assert(dG[i].first > dG[i - 1].first);
		(dG[i].second += dG[i - 1].second) %= P;
	}
	
	while (T--) {
		ll x; rd(x);
		if (x <= 20) {
			printf("%lld %lld\n", f[x], g[x]);
			continue;
		}
		auto itF = --upper_bound(dF.begin(), dF.end(), make_pair(x, LONG_LONG_MAX)),
			itG = --upper_bound(dG.begin(), dG.end(), make_pair(x, LONG_LONG_MAX));
		printf("%lld %lld\n", itF->second, itG->second);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 263ms
memory: 14548kb

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: 262ms
memory: 16060kb

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: 254ms
memory: 16628kb

input:

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

output:

2023 2023
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

result:

wrong answer 1st numbers differ - expected: '0', found: '2023'