QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#635691#9451. Expected Waiting Timeucup-team3564#AC ✓748ms102836kbC++202.3kb2024-10-12 20:36:362024-10-12 20:36:39

Judging History

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

  • [2024-10-12 20:36:39]
  • 评测
  • 测评结果:AC
  • 用时:748ms
  • 内存:102836kb
  • [2024-10-12 20:36:36]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define int long long
#define debug cerr << "\33[32m[" << __LINE__ << "]\33[m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T &x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T &x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = - f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = 2e6 + 10;
int n, MOD, b[N], a[N], A, B, p[N], s[N];
inline int& add(int &x, ll y) {return x = (x + y) % MOD;}
int fac[N], ifac[N], inv[N];
inline void binom(int x) {
	fac[0] = ifac[0] = inv[1] = 1;
	F(i, 2, x) inv[i] = (ll) (MOD - MOD / i) * inv[MOD % i] % MOD;
	F(i, 1, x) fac[i] = (ll) fac[i - 1] * i % MOD, ifac[i] = (ll) ifac[i - 1] * inv[i] % MOD;
}
inline int C(int x, int y) {return x < y || y < 0 ? 0 : (ll) fac[x] * ifac[y] % MOD * ifac[x - y] % MOD;}
inline int power(int x, int y = MOD - 2) {
	int ans = 1;
	for (; y; x = (ll) x * x % MOD, y >>= 1)
		if (y & 1) ans = (ll) ans * x % MOD;
	return ans;
}
void zhk() {
	read(n), read(MOD), read(b[0]), read(A), read(B);
	binom(2 * n + 5);
	p[0] = 1;
	F(i, 1, n) p[i] = (C(i * 2, i) - C(i * 2, i - 1) + MOD) % MOD;
	F(i, 1, n) s[i] = (s[i - 1] + (ll) p[i - 1] * p[n - i]) % MOD;
	int ans = 0;
	F(i, 1, n * 2) {
		b[i] = ((ll) A * b[i - 1] + B) % MOD;
		a[i] = (a[i - 1] + b[i] + 1) % MOD;
		// debug << a[i] << " " << b[i] << endl;
		if (i <= n) {
			ll t = s[i / 2];
			// debug << i << ' ' << t << endl;
			add(ans, (ll) t * a[i]);
			add(ans, (ll) (p[n] - t + MOD) % MOD * (MOD - a[i]));
		} else {
			ll t = s[(2 * n - i + 1) / 2];
			// debug << i << ' ' << t << endl;
			// debug << (2 * n - i) / 2 << " " << t << endl;
			add(ans, (ll) t * (MOD - a[i]));
			add(ans, (ll) (p[n] - t + MOD) % MOD * a[i]);
		}
	}
	// debug << n << " " << p[n] << endl;
	cout << (ll) ans * power(p[n]) % MOD << '\n';
}
signed main() {
	int _ = 1;
	cin >> _;
	while (_--) zhk();
	return 0;
}
/* why?
*/

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 13888kb

input:

5
1 1000000007 0 1 0
2 1000000007 0 1 1
2 7 5 2 3
3 31 15 6 24
20 1000000007 0 1 0

output:

1
12
1
21
879705565

result:

ok 5 number(s): "1 12 1 21 879705565"

Test #2:

score: 0
Accepted
time: 711ms
memory: 13968kb

input:

4400
3954 1000000007 0 1 0
1306 1000000007 0 1 0
3774 1000000007 0 1 0
3345 1000000007 0 1 0
891 1000000007 0 1 0
2462 1000000007 0 1 0
237 1000000007 0 1 0
26 1000000007 0 1 0
2510 1000000007 0 1 0
637 1000000007 0 1 0
3250 1000000007 0 1 0
3447 1000000007 0 1 0
1222 1000000007 0 1 0
133 1000000007...

output:

440618338
378292891
979368645
915766295
343598158
80867595
161627927
517387931
396936703
42785642
945720545
764273281
186237656
635777911
164064906
548455037
991964184
468137124
561243246
118562285
856945294
642467240
23673926
808943705
897417615
462422554
656411244
204288121
997894281
244685651
762...

result:

ok 4400 numbers

Test #3:

score: 0
Accepted
time: 748ms
memory: 102836kb

input:

1019
338 1863833207 1820742817 1507924477 1822273457
770 1386304741 1088481071 1216187083 170973217
597 1604266739 620750027 196415899 456280997
105 1008587891 184044403 24836083 926135599
357 1165127407 440925347 1103369747 912263123
82 1639766993 263045351 631010551 1412721139
928 1715915153 25383...

output:

1532578211
839037587
1047387343
827110887
825754860
1399761197
267796211
1563605211
1628148612
510782452
1009499206
977929696
466163317
246777775
1781337180
700999207
522771237
42312781
172374583
319038379
563256698
1400403161
22552986
1408276343
558752169
1050819260
174447415
844160548
1382940913
1...

result:

ok 1019 numbers

Test #4:

score: 0
Accepted
time: 737ms
memory: 23760kb

input:

217
31752 1623636743 381890923 885513569 842557939
44560 1671300349 1133398261 1076377361 138151151
98395 1887613031 1552853849 1167776639 1748368931
38388 1221893927 524645339 598717199 864504559
46484 1161165839 833729009 348202331 407607601
14134 1500136753 247946861 1029519499 420912461
42361 12...

output:

921943129
1651287678
1204818336
685557670
348324702
1348834532
684106754
1802861733
294146103
1181847835
393402724
771264676
1357541910
336262290
1519052686
965265375
164416232
536332209
664177339
279762508
172270575
296113856
676553568
56580590
1662307723
551032870
849878353
899756098
1043540760
65...

result:

ok 217 numbers

Test #5:

score: 0
Accepted
time: 736ms
memory: 22812kb

input:

209
29771 1072350767 215063557 929759989 884416571
55201 1330151437 375869047 1089916759 1006803043
44446 1255569503 974485139 1100573447 468049237
38112 1088575729 690554509 139043089 318478729
59665 1197676111 958924997 1062562733 504417349
26297 1267535141 800679281 972314209 417253079
19848 1470...

output:

1019773842
530587777
960231793
799694163
777561611
5502176
357632543
758954057
966358573
1023410809
949841520
1495179331
1580320049
173875471
2220116
469298866
1337750009
369625733
747522220
143937247
1286370836
135996013
210044979
1583248565
657653951
1035620126
160616212
193166047
147168296
194451...

result:

ok 209 numbers

Test #6:

score: 0
Accepted
time: 739ms
memory: 22468kb

input:

191
4581 1215490597 542057431 695641117 341312327
76198 1830024701 1063458349 588883499 1260572737
76694 1445111947 1069466003 941483509 268919069
92431 1384691513 15731591 390776461 943271249
63234 1097808793 204272807 857954509 763222181
26427 1746295877 743699191 1671886939 1655403307
91012 19997...

output:

660812054
1707568418
155249600
645552623
671226426
50129037
971925203
1638809868
463571080
143058581
403506184
767222482
666935871
1092771100
416048275
1536775747
475955650
73199758
578511368
51576569
1380151783
515363742
1021989523
892069331
1088408017
1337534689
715624643
1241212077
730954505
1286...

result:

ok 191 numbers

Extra Test:

score: 0
Extra Test Passed