QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#580267#9380. Match000226AC ✓90ms4920kbC++173.2kb2024-09-21 20:49:202024-09-21 20:49:20

Judging History

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

  • [2024-09-21 20:49:20]
  • 评测
  • 测评结果:AC
  • 用时:90ms
  • 内存:4920kb
  • [2024-09-21 20:49:20]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define lep(i, l, r) for(int i = (l); i <= (r); i ++)
#define rep(i, l, r) for(int i = (l); i >= (r); i --)
#define Lep(i, l, r) for(int i = (l); i <  (r); i ++)
#define debug(...) fprintf (stderr, __VA_ARGS__)

using i64 = long long;
using ld = long double;
using ui64 = unsigned long long;

const int P = 998244353;
inline int mod(int x) { return x + (x >> 31 & P); }
inline void pls(int &x, int y) { x = mod(x + y - P); }
inline void sub(int &x, int y) { x = mod(x - y); }
inline int  add(int x, int y) { return mod (x + y - P); }
inline int  dec(int x, int y) { return mod (x - y); }

inline int power(int x, int k) {
	int res = 1;
	while(k) {
		if (k & 1) res = 1ll * res * x % P;
		x = 1ll * x * x % P; k >>= 1;
	} return res;
}

/*

f(a, b, k, i)

for bit

k = 0
0 1 / 1 0 
0 0 / 1 1

*/

const int N = 400 + 5;

int C[N][N], fac[N];
void init(int n = 400) {
	C[0][0] = 1;
	fac[0] = 1;
	lep (i, 1, n) fac[i] = 1ll * fac[i - 1] * i % P;
	lep (i, 1, n) {
		C[i][0] = 1;
		lep (j, 1, i) {
			C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]);
		}
	}
}

int n;
i64 k;

vector<int> solve(vector<i64> a, vector<i64> b, i64 k, int bit) {
	if (a.size() == 0 || b.size() == 0) return {1};

	if (bit < 0) {
		int sz = min (a.size(), b.size());
		vector<int> res(sz + 1);
		for (int i = 0; i <= sz; i ++) {
			res[i] = C[a.size()][i] * 1ll * C[b.size()][i] % P * fac[i] % P;
		}
		
		return res;
	}

	if (! (k & (1ll << bit)) ) {

		vector<i64> a0, a1, b0, b1;
		for (auto x : a) {
			if (x & (1ll << bit)) a1.push_back(x);
			else a0.push_back(x);
		}
		for (auto x : b) {
			if (x & (1ll << bit)) b1.push_back(x);
			else b0.push_back(x);
		}

		auto dpa0b0 = solve(a0, b0, k, bit - 1);
		auto dpa1b1 = solve(a1, b1, k, bit - 1);
		
		int sz = min(a.size(), b.size());
		vector<int> res(sz + 1);

		for (int i = 0; i < dpa0b0.size(); i ++)
			for (int j = 0; j < dpa1b1.size(); j ++) {
				int tmp = dpa0b0[i] * 1ll * dpa1b1[j] % P;

				int A0 = a0.size() - i, A1 = a1.size() - j, B0 = b0.size() - i, B1 = b1.size() - j;
				int x = min(A0, B1), y = min(A1, B0);

				lep (p, 0, x) lep (q, 0, y) {
					int v = 1ll * tmp * C[A0][p] % P * C[B1][p] % P * C[B0][q] % P * C[A1][q] % P * fac[p] % P * fac[q] % P;
					pls(res[i + j + p + q], v);
				}
			}

		return res;

	} else {
		vector<i64> a0, a1, b0, b1;
		for (auto x : a) {
			if (x & (1ll << bit)) a1.push_back(x);
			else a0.push_back(x);
		}
		for (auto x : b) {
			if (x & (1ll << bit)) b1.push_back(x);
			else b0.push_back(x);
		}

		auto dpa0b1 = solve(a0, b1, k, bit - 1);
		auto dpa1b0 = solve(a1, b0, k, bit - 1);

		int sz = min(a.size(), b.size());
		vector<int> res(sz + 1);
		for (int i = 0; i < dpa0b1.size(); i ++)
			for (int j = 0; j < dpa1b0.size(); j ++) 
				pls(res[i + j], dpa0b1[i] * 1ll * dpa1b0[j] % P);

		return res;
	}
}

int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	init();
	cin >> n >> k;
	vector<i64> a(n), b(n);
	for (auto &x : a) cin >> x;
	for (auto &x : b) cin >> x;
	auto dp = solve (a, b, k, 60);
	lep (i, 1, n) cout << dp[i] << '\n';
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4260kb

input:

9 5
1 7 2 8 4 9 2 5 10
1 3 2 4 5 8 8 8 9

output:

51
1034
10768
62195
200965
348924
294444
97344
7200

result:

ok 9 lines

Test #2:

score: 0
Accepted
time: 90ms
memory: 4248kb

input:

200 569102225177443347
1103663383682482176 1103381908705771520 1099441259031822336 1098878309078401024 1089871109823660032 1080863910568919040 1074108511127863296 1071856711314178048 1069041961547071488 1068479011593650176 1067353111686807552 1062849512059437056 1049338713177325568 10448351135499550...

output:

20506
208107723
47878304
53020813
972282728
933586852
658157196
670189811
957980024
366179738
217980591
967482558
833450149
987731802
260904367
5263881
600332344
906061351
658256294
93700706
421323952
178075016
219871690
986880524
848776106
191185484
641917326
576497440
908609746
349728876
606714342...

result:

ok 200 lines

Test #3:

score: 0
Accepted
time: 7ms
memory: 4280kb

input:

200 1098723432450995412
972777519512027136 936748722493063168 864691128455135232 860187528827764736 857935729014079488 856246879153815552 855683929200394240 851180329573023744 848928529759338496 847802629852495872 847310048643252224 847239679899074560 846676729945653248 828662331436171264 8280993814...

output:

8320
34035512
428014253
916072411
696504298
748377440
32424677
188402417
233587075
130639672
759476380
546285625
187068736
159002787
131866334
381530906
133126344
373727612
923311054
725293681
718162548
39511135
322320638
44709653
156884882
285926751
787179409
282967016
153092344
615721347
950855850...

result:

ok 200 lines

Test #4:

score: 0
Accepted
time: 1ms
memory: 4920kb

input:

200 1
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

3072
4412928
940025853
665370743
752672705
581549490
41990996
541401698
170451802
26584141
220983766
844620126
64506869
137621326
418866920
351049174
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 200 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 4856kb

input:

200 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

40000
792020000
319908096
286630939
515085548
95626140
472749362
800008042
594973486
139901984
847967250
125664877
254232250
419486325
204481923
979660340
41873095
540955890
585129047
205968776
196086667
674391130
737319172
669580034
973843015
207125612
331414909
119844754
24879477
990932807
8476927...

result:

ok 200 lines

Extra Test:

score: 0
Extra Test Passed