QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#544658#4318. 高性能计算导论集群登录密码复杂性策略251SecAC ✓276ms48244kbC++143.4kb2024-09-02 19:23:412024-09-02 19:23:41

Judging History

This is the latest submission verdict.

  • [2024-09-02 19:23:41]
  • Judged
  • Verdict: AC
  • Time: 276ms
  • Memory: 48244kb
  • [2024-09-02 19:23:41]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 1e9 + 7;
ll QPow(ll a, ll b) {
	ll res = 1;
	for (; b; b >>= 1, a = a * a % P) if (b & 1) res = res * a % P;
	return res;
}
struct Poly {
	vector<ll> w;
	Poly() {}
	Poly(int sz) : w(sz) {}
	Poly(vector<ll> w) : w(w) {}
	ll &operator[](int i) { return w[i]; }
	ll operator[](int i) const { return w[i]; }
	int size() const { return w.size(); }
	void resize(int x) { w.resize(x); }
	Poly operator*(const Poly &b) const {
		Poly res(size() + b.size() - 1);
		for (int i = 0; i < size(); i++) {
			for (int j = 0; j < b.size(); j++) {
				res[i + j] += w[i] * b[j] % P;
			}
		}
		for (int i = 0; i < res.size(); i++) res[i] %= P;
		return res;
	}
	Poly operator%(const Poly &b) const {
		if (size() < b.size()) return *this;
		Poly a = *this;
		ll iv = QPow(b.w.back(), P - 2);
		int m = b.size() - 1;
		for (int i = size() - 1; i >= m; i--) {
			if (!a[i]) continue;
			ll w = a[i] * iv % P;
			for (int j = 0; j <= m; j++) (a[i - j] -= w * b[m - j] % P) %= P;
		}
		for (int i = 0; i < a.size(); i++) a[i] = (a[i] % P + P) % P;
		while (a.size() && !a.w.back()) a.w.pop_back();
		return a;
	}
};
namespace BM {
	vector<ll> cur, lst;
	ll del, fail;
	void UpdLst(vector<ll> t, ll tdel, ll tfail) {
		if ((int)t.size() - tfail < (int)lst.size() - fail) fail = tfail, del = tdel, lst = t;
	}
	vector<ll> Solve(ll *a, int n) {
		for (int i = 1; i <= n; i++) {
			ll d = a[i];
			for (int j = 0; j < cur.size(); j++) d -= a[i - j - 1] * cur[j] % P;
			d = (d % P + P) % P;
			if (!d) continue;
			vector<ll> tcur = cur;
			if (!fail) cur.resize(i);
			else {
				ll w = d * del % P;
				if (cur.size() < i - fail + lst.size()) cur.resize(i - fail + lst.size());
				(cur[i - fail - 1] += w) %= P;
				for (int j = 0; j < lst.size(); j++) (cur[i - fail + j] += (P - lst[j]) * w % P) %= P;
			}
			UpdLst(tcur, QPow(d, P - 2), i);
		}
		for (int i = 0; i < cur.size(); i++) cur[i] = (P - cur[i]) % P;
		reverse(cur.begin(), cur.end());
		cur.push_back(1);
		return cur;
	}
}
int l, r, a, b;
ll f[1005][36][26][2][3], s[1005];
void Upd(ll &x, ll y) { (x += y) %= P; }
ll Calc(Poly f, int n) {
	Poly a; a.resize(2), a[1] = 1;
	Poly res; res.resize(1), res[0] = 1;
	for (; n; n >>= 1, a = a * a % f) if (n & 1) res = res * a % f;
	ll ans = 0;
	for (int i = 0; i < res.size(); i++) ans += res[i] * s[i] % P;
	return ans % P;
}
int main() {
	scanf("%d%d%d%d", &l, &r, &a, &b);
	for (int i = 0; i < 36; i++) f[1][i][1][0][0] = 1 + (i > 9);
	for (int i = 1; i <= 1000; i++) {
		for (int j = 0; j < 36; j++) {
			for (int k = 1; k < 26; k++) {
				for (int x = 0; x < 2; x++) {
					for (int y = 0; y < 3; y++) {
						if (f[i][j][k][x][y] && ((!y && k < a) || (y && k < b))) {
							ll w = f[i][j][k][x][y];
							for (int z = 0; z < 36; z++) {
								if (z == j) Upd(f[i + 1][z][!y ? k + 1 : 2][x][0], w);
								else if (z == j + 1 && j != 9) Upd(f[i + 1][z][y == 1 ? k + 1 : 2][x][1], w);
								else if (z == j - 1 && j != 10) Upd(f[i + 1][z][y == 2 ? k + 1 : 2][x][2], w);
								else Upd(f[i + 1][z][1][x || ((j < 10) != (z < 10))][0], w);
								if (z > 9) Upd(f[i + 1][z][1][x || ((j < 10) != (z < 10))][0], w);
							}
							if (x) Upd(s[i], w);
						}
					}
				}
			}
		}
	}
	for (int i = 1; i <= 1000; i++) Upd(s[i], s[i - 1]);
	auto g = BM::Solve(s - 1, 1001);
	printf("%lld\n", (Calc(g, r) - Calc(g, l - 1) + P) % P);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 201ms
memory: 47972kb

input:

1 1 6 14

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 248ms
memory: 47944kb

input:

107140316 406944816 6 13

output:

192490578

result:

ok single line: '192490578'

Test #3:

score: 0
Accepted
time: 262ms
memory: 47936kb

input:

779830894 854589440 6 16

output:

142613425

result:

ok single line: '142613425'

Test #4:

score: 0
Accepted
time: 259ms
memory: 47944kb

input:

820947500 832029867 6 25

output:

334755990

result:

ok single line: '334755990'

Test #5:

score: 0
Accepted
time: 256ms
memory: 47792kb

input:

531362238 979634526 6 26

output:

628390760

result:

ok single line: '628390760'

Test #6:

score: 0
Accepted
time: 220ms
memory: 47820kb

input:

580120176 615170139 2 24

output:

282232431

result:

ok single line: '282232431'

Test #7:

score: 0
Accepted
time: 181ms
memory: 47912kb

input:

609381043 653379818 2 13

output:

803190890

result:

ok single line: '803190890'

Test #8:

score: 0
Accepted
time: 227ms
memory: 47924kb

input:

137169046 882295293 4 17

output:

487036819

result:

ok single line: '487036819'

Test #9:

score: 0
Accepted
time: 251ms
memory: 47876kb

input:

394493680 588692626 4 20

output:

99083012

result:

ok single line: '99083012'

Test #10:

score: 0
Accepted
time: 229ms
memory: 47948kb

input:

722139370 843455409 3 20

output:

187518918

result:

ok single line: '187518918'

Test #11:

score: 0
Accepted
time: 133ms
memory: 47932kb

input:

154981461 843412687 4 6

output:

799306362

result:

ok single line: '799306362'

Test #12:

score: 0
Accepted
time: 259ms
memory: 48236kb

input:

999999999 1000000000 6 15

output:

227192434

result:

ok single line: '227192434'

Test #13:

score: 0
Accepted
time: 83ms
memory: 48168kb

input:

892758405 994840518 4 4

output:

945734811

result:

ok single line: '945734811'

Test #14:

score: 0
Accepted
time: 276ms
memory: 48224kb

input:

536870911 973078527 6 14

output:

598094194

result:

ok single line: '598094194'

Test #15:

score: 0
Accepted
time: 268ms
memory: 47940kb

input:

536870912 973078527 6 15

output:

803373842

result:

ok single line: '803373842'

Test #16:

score: 0
Accepted
time: 253ms
memory: 47932kb

input:

333333333 333333333 6 14

output:

867976976

result:

ok single line: '867976976'

Test #17:

score: 0
Accepted
time: 17ms
memory: 47768kb

input:

66025887 800841810 2 2

output:

141443913

result:

ok single line: '141443913'

Test #18:

score: 0
Accepted
time: 122ms
memory: 47948kb

input:

37821660 191789705 5 5

output:

232561519

result:

ok single line: '232561519'

Test #19:

score: 0
Accepted
time: 205ms
memory: 47940kb

input:

668000825 930344057 6 9

output:

597839207

result:

ok single line: '597839207'

Test #20:

score: 0
Accepted
time: 209ms
memory: 48244kb

input:

692413584 717112316 6 10

output:

912537114

result:

ok single line: '912537114'