QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375247#8312. Fly Me To The MoonPetroTarnavskyiAC ✓1982ms53456kbC++205.2kb2024-04-03 03:09:032024-04-03 03:09:04

Judging History

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

  • [2024-04-03 03:09:04]
  • 评测
  • 测评结果:AC
  • 用时:1982ms
  • 内存:53456kb
  • [2024-04-03 03:09:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 1 << 10;

/**
 * Description: $\text{GEN}^{\frac{\text{LEN}}{2}} = \text{mod} - 1$. \\
 * ULL mod = 9223372036737335297, $\text{GEN} = 3^{\frac{\text{mod} - 1}{\text{LEN}}}, \text{LEN} \le 2^{24}$.
 */
const int mod = 998244353;

void updAdd(int& a, int b)
{
	a += b;
	if(a >= mod)
		a -= mod;
}

int add(int a, int b)
{
	return a + b < mod ? a + b : a + b - mod;
}
int sub(int a, int b)
{
	return a - b >= 0 ? a - b : a - b + mod;
}
int mult(int a, int b)
{
	return (LL)a * b % mod;
}
int binpow(int a, int n)
{
	int res = 1;
	while(n)
	{
		if(n & 1)
			res = mult(res, a);
		a = mult(a, a);
		n /= 2;
	}
	return res;
}

const int LEN = 1 << 23;
const int GEN = 31;
const int IGEN = binpow(GEN, mod - 2);

VI mult(VI a, int x)
{
	FOR(i, 0, SZ(a))
		a[i] = mult(a[i], x);
	return a;
}
VI add(VI a, VI b)
{
	assert(SZ(a) == SZ(b));
	VI c(SZ(a));
	FOR(i, 0, SZ(a))
		c[i] = add(a[i], b[i]);
	return c;
}
VI sub(VI a, VI b)
{
	assert(SZ(a) == SZ(b));
	VI c(SZ(a));
	FOR(i, 0, SZ(a))
		c[i] = sub(a[i], b[i]);
	return c;
}
VI mult(VI a, VI b)
{
	assert(SZ(a) == SZ(b));
	VI c(SZ(a));
	FOR(i, 0, SZ(a))
		c[i] = mult(a[i], b[i]);
	return c;	
}


template<class T>
void fft(vector<T>& a, bool inv)
{
	int lg = __builtin_ctz(SZ(a));
	FOR(i, 0, SZ(a))
	{
		int k = 0;
		FOR(j, 0, lg)
			k |= ((i >> j) & 1) << (lg - j - 1);
		if(i < k)
			swap(a[i], a[k]);
	}
	for(int len = 2; len <= SZ(a); len *= 2)
	{
		int ml = binpow(inv ? IGEN : GEN, LEN / len);
		for(int i = 0; i < SZ(a); i += len)
		{
			int pw = 1;
			FOR(j, 0, len / 2)
			{
				auto v = a[i + j];
				auto u = mult(a[i + j + len / 2], pw);
				
				a[i + j] = add(v, u);
				a[i + j + len / 2] = sub(v, u);
			
				pw = mult(pw, ml);
			}
		}
	}
	if(inv)
	{
		int m = binpow(SZ(a), mod - 2);
		FOR(i, 0, SZ(a))
			a[i] = mult(a[i], m);
	}
}


VI multFFT(VI a, VI b)
{
	int sz = 0;
	int sum = SZ(a) + SZ(b) - 1;
	while((1 << sz) < sum) sz++;
	a.resize(1 << sz);
	b.resize(1 << sz);
	
	fft(a, false);
	fft(b, false);
	
	FOR(i, 0, SZ(a))
		a[i] = mult(a[i], b[i]);
	
	fft(a, true);
	a.resize(sum);
	return a;
}

vector<VI> mult(vector<VI> a, vector<VI> b)
{
	int szX = 0;
	int sumX = SZ(a) + SZ(b) - 1;
	while((1 << szX) < sumX) szX++;
	a.resize(1 << szX);
	b.resize(1 << szX);
	
	int szY = 0;
	int sumY = SZ(a[0]) + SZ(b[0]) - 1;
	while((1 << szY) < sumY) szY++;
	FOR(i, 0, 1 << szX)
	{
		a[i].resize(1 << szY);
		b[i].resize(1 << szY);
		fft(a[i], false);
		fft(b[i], false);
	}
	
	fft(a, false);
	fft(b, false);
	
	FOR(i, 0, SZ(a))
		a[i] = mult(a[i], b[i]);
	
	fft(a, true);
	a.resize(sumX);
	FOR(i, 0, sumX)
	{
		fft(a[i], true);
		a[i].resize(sumY);
	}
	return a;
}


VI inverse(const VI& a, int k)
{
	assert(SZ(a) == k && a[0] != 0);
	if(k == 1)
		return {binpow(a[0], mod - 2)};  
	
	VI ra = a;
	FOR(i, 0, SZ(ra))
		if(i & 1)
			ra[i] = sub(0, ra[i]);    
	
	int nk = (k + 1) / 2;
	VI t = multFFT(a, ra);
	t.resize(k);
	
	FOR(i, 0, nk)
		t[i] = t[2 * i];
  
	t.resize(nk);
	t = inverse(t, nk);
	t.resize(k);
  
	RFOR(i, nk, 1)
	{
		t[2 * i] = t[i];
		t[i] = 0;
	}
	
	VI res = multFFT(ra, t);
	res.resize(k);
	return res;
}

vector<VI> inverse(const vector<VI>& a, int kx, int ky)
{
	assert(SZ(a) == kx && SZ(a[0]) == ky && a[0][0] != 0);
	if(kx == 1)
		return {inverse(a[0], ky)};  
	
	vector<VI> ra = a;
	FOR(i, 0, SZ(ra))
		if(i & 1)
		{
			FOR(j, 0, ky)
				ra[i][j] = sub(0, ra[i][j]);    
		}
	
	int nk = (kx + 1) / 2;
	vector<VI> t = mult(a, ra);
	t.resize(kx);
	FOR(i, 0, kx)
		t[i].resize(ky);
	
	FOR(i, 0, nk)
		t[i] = t[2 * i];
  
	t.resize(nk);
	t = inverse(t, nk, ky);
	t.resize(kx);
  
	RFOR(i, nk, 1)
	{
		t[2 * i] = t[i];
		t[i] = VI(ky);
	}
	
	vector<VI> res = mult(ra, t);
	res.resize(kx);
	FOR(i, 0, kx)
		res[i].resize(ky);
		
	return res;
}


int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);

	int n, m;
	cin >> n >> m;
	
	VI d(n);
	FOR(i, 0, n)
		cin >> d[i];
	
	vector<VI> G(N, VI(N));
	FOR(i, 0, n)
	{
		FOR(dx, 0, d[i] + 1)
		{
			int dy = sqrt(d[i] * d[i] - dx * dx);
			
			updAdd(G[dx][0], 1);
			updAdd(G[dx][dy + 1], mod - 1);
		}
	}
	FOR(i, 0, N)
		FOR(j, 1, N)
			updAdd(G[i][j], G[i][j - 1]);
	G[0][0] = 0;
	
	auto D = G;
	FOR(i, 0, N)
		FOR(j, 0, N)
			D[i][j] = sub(0, G[i][j]);
	D[0][0] = 1;
	
		
	auto ways = inverse(D, N, N);	
	cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
	
	vector<PII> pts(m);
	FOR(i, 0, m)
		cin >> pts[i].F >> pts[i].S;
	pts.PB({1000, 1000});
	sort(ALL(pts));
	
	VI dp(m + 1);
	FOR(i, 0, m + 1)
	{
		dp[i] = ways[pts[i].F][pts[i].S];
		FOR(j, 0, i)
		{
			if(pts[j].S <= pts[i].S)
				dp[i] = sub(dp[i], mult(ways[pts[i].F - pts[j].F][pts[i].S - pts[j].S], dp[j]));
		}
	}
	cout << dp.back() << "\n";
	
	


	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1953ms
memory: 53228kb

input:

1 0
1

output:

472799582

result:

ok single line: '472799582'

Test #2:

score: 0
Accepted
time: 1950ms
memory: 53316kb

input:

1 1
1
500 500

output:

447362327

result:

ok single line: '447362327'

Test #3:

score: 0
Accepted
time: 1957ms
memory: 53316kb

input:

1 0
2

output:

277036758

result:

ok single line: '277036758'

Test #4:

score: 0
Accepted
time: 1982ms
memory: 53212kb

input:

1 1
402
305 914

output:

902644270

result:

ok single line: '902644270'

Test #5:

score: 0
Accepted
time: 1968ms
memory: 53184kb

input:

1 10
819
767 245
718 363
832 537
648 98
622 692
995 435
641 522
1000 524
220 848
657 772

output:

728068212

result:

ok single line: '728068212'

Test #6:

score: 0
Accepted
time: 1974ms
memory: 53272kb

input:

1 100
51
779 670
872 824
190 278
764 704
804 857
215 41
43 329
735 229
733 463
594 905
740 538
245 254
556 174
523 388
0 722
464 464
62 31
554 24
935 438
738 751
250 849
803 437
856 887
745 187
52 845
855 613
344 256
705 694
897 743
682 796
966 471
268 430
937 160
629 629
641 98
329 470
49 650
463 6...

output:

517392311

result:

ok single line: '517392311'

Test #7:

score: 0
Accepted
time: 1970ms
memory: 53428kb

input:

1 1000
60
654 936
693 232
484 105
592 624
118 698
490 632
411 327
487 16
51 399
408 241
39 574
39 994
777 881
506 360
445 779
186 319
651 673
939 828
845 950
81 613
747 548
176 72
283 422
866 639
256 790
168 672
551 308
265 204
542 587
800 837
299 347
485 296
410 832
894 123
785 795
705 20
360 762
2...

output:

226697311

result:

ok single line: '226697311'

Test #8:

score: 0
Accepted
time: 1979ms
memory: 53268kb

input:

10 1
668 228 643 930 253 838 234 427 994 555
769 217

output:

706413856

result:

ok single line: '706413856'

Test #9:

score: 0
Accepted
time: 1972ms
memory: 53288kb

input:

10 10
210 428 49 365 404 258 968 520 718 191
240 37
665 794
444 403
492 764
38 1
549 456
32 847
95 499
490 875
983 553

output:

866541606

result:

ok single line: '866541606'

Test #10:

score: 0
Accepted
time: 1976ms
memory: 53264kb

input:

10 100
234 300 17 327 773 617 460 612 25 853
332 250
788 770
578 304
378 268
648 555
820 600
989 317
319 383
904 612
22 17
511 183
896 125
963 958
722 984
681 766
420 198
492 686
285 634
15 40
531 325
414 10
581 72
93 528
771 235
906 696
255 785
493 858
804 452
899 585
824 334
798 579
161 357
615 20...

output:

857409499

result:

ok single line: '857409499'

Test #11:

score: 0
Accepted
time: 1980ms
memory: 53268kb

input:

10 1000
433 514 452 478 193 55 745 40 365 655
143 730
490 83
890 273
699 469
293 532
971 535
204 959
370 992
238 858
306 647
273 701
661 560
9 857
27 635
564 666
83 239
640 989
738 290
316 584
687 656
587 263
969 245
782 395
958 638
551 128
570 105
776 244
442 723
708 963
527 978
714 479
331 613
373...

output:

99542416

result:

ok single line: '99542416'

Test #12:

score: 0
Accepted
time: 1980ms
memory: 53304kb

input:

100 1
164 898 529 41 491 208 409 533 860 311 271 48 914 918 256 757 19 647 652 343 880 995 504 120 864 995 499 86 285 823 793 816 445 147 923 501 314 789 733 861 507 305 623 566 249 669 933 528 955 461 511 665 874 472 497 331 957 313 756 665 463 735 595 101 348 397 471 477 479 315 180 409 183 739 91...

output:

30592831

result:

ok single line: '30592831'

Test #13:

score: 0
Accepted
time: 1972ms
memory: 53240kb

input:

100 10
689 629 128 228 488 666 155 67 260 881 474 235 69 580 605 622 791 551 274 3 90 106 875 180 905 787 566 632 75 865 300 521 61 618 602 575 487 806 667 276 914 193 643 646 760 397 517 249 252 214 991 530 709 708 817 220 224 692 146 407 547 720 515 772 131 754 745 778 583 773 943 557 602 644 954 ...

output:

523635681

result:

ok single line: '523635681'

Test #14:

score: 0
Accepted
time: 1967ms
memory: 53268kb

input:

100 100
95 994 231 565 335 495 270 478 781 36 769 597 839 828 489 262 736 223 835 21 136 11 865 239 113 534 479 687 91 470 143 682 24 697 206 387 449 381 260 792 863 9 16 506 131 690 106 905 470 48 927 86 665 366 545 808 567 317 124 144 734 193 826 332 82 954 272 783 994 381 279 679 809 809 4 559 94...

output:

226829327

result:

ok single line: '226829327'

Test #15:

score: 0
Accepted
time: 1979ms
memory: 53268kb

input:

100 1000
122 81 18 561 601 538 804 877 55 943 955 751 206 881 249 227 640 846 6 935 544 383 628 688 609 898 25 669 837 272 848 595 599 376 280 855 953 122 779 687 751 29 97 18 666 571 123 11 223 527 88 26 901 493 923 371 947 411 378 228 423 816 497 219 439 228 573 183 156 144 426 610 11 849 310 893 ...

output:

801536119

result:

ok single line: '801536119'

Test #16:

score: 0
Accepted
time: 1965ms
memory: 53224kb

input:

1000 1
347 291 904 415 766 616 892 80 210 2 855 907 49 874 156 630 623 472 636 474 871 591 458 258 398 844 133 304 822 802 393 360 789 888 566 875 355 777 944 622 831 195 941 968 259 49 650 927 564 305 662 956 187 967 70 762 390 616 264 187 383 832 543 507 348 693 181 939 350 465 84 719 138 779 52 7...

output:

949510956

result:

ok single line: '949510956'

Test #17:

score: 0
Accepted
time: 1966ms
memory: 53324kb

input:

1000 10
550 515 534 170 50 545 557 637 312 64 715 686 618 743 11 58 829 992 668 519 314 9 961 173 719 405 249 728 772 793 856 983 239 647 565 328 784 902 498 850 773 687 376 473 447 746 472 533 20 959 762 523 875 246 770 747 307 975 102 24 372 883 833 635 260 97 996 793 539 145 607 568 95 453 972 13...

output:

543205049

result:

ok single line: '543205049'

Test #18:

score: 0
Accepted
time: 1946ms
memory: 53328kb

input:

1000 100
1000 561 798 648 552 683 817 828 176 516 923 627 308 136 362 867 562 911 478 12 28 965 706 374 666 360 506 416 69 262 983 26 61 532 580 724 436 103 125 412 561 519 907 517 318 215 801 322 123 495 706 503 160 938 273 241 871 120 158 360 535 141 528 628 674 664 326 950 656 285 77 634 146 756 ...

output:

557427721

result:

ok single line: '557427721'

Test #19:

score: 0
Accepted
time: 1956ms
memory: 53456kb

input:

1000 1000
520 999 552 931 480 348 671 930 534 80 510 4 176 583 686 73 81 239 523 968 447 468 517 286 523 285 929 366 764 533 310 580 524 635 33 153 49 146 57 58 54 250 115 705 207 229 111 266 776 787 273 191 143 342 257 157 38 663 995 53 586 135 360 540 78 479 884 435 825 808 438 295 523 380 810 658...

output:

410377569

result:

ok single line: '410377569'

Test #20:

score: 0
Accepted
time: 1962ms
memory: 53440kb

input:

1000 1000
630 843 959 696 75 966 691 982 390 44 863 380 467 293 94 96 415 411 161 497 844 109 629 520 209 248 672 754 608 553 552 447 503 868 292 854 848 512 849 15 120 497 70 671 707 29 952 544 302 159 863 886 788 160 63 27 27 600 912 555 476 809 511 225 182 701 195 657 363 275 392 691 249 590 135 ...

output:

625394011

result:

ok single line: '625394011'

Test #21:

score: 0
Accepted
time: 1960ms
memory: 53252kb

input:

1000 1000
553 29 586 864 467 447 950 526 232 354 866 48 566 98 600 10 667 754 262 683 344 374 641 56 33 945 141 175 255 575 341 165 806 941 985 209 79 652 395 86 327 794 161 869 198 400 815 64 457 597 882 833 561 209 725 745 450 363 808 353 933 92 4 988 558 370 728 259 934 238 79 976 474 174 16 955 ...

output:

373678731

result:

ok single line: '373678731'

Test #22:

score: 0
Accepted
time: 1954ms
memory: 53248kb

input:

1000 1000
1 186 432 753 430 425 46 836 652 389 195 429 575 809 901 935 24 697 358 545 627 975 980 343 7 167 762 519 298 347 118 422 923 855 577 657 470 750 138 572 572 275 835 54 672 25 482 435 330 700 450 353 264 854 95 907 824 835 494 345 304 733 290 366 983 672 24 169 649 535 740 21 454 437 554 8...

output:

663460363

result:

ok single line: '663460363'

Test #23:

score: 0
Accepted
time: 1947ms
memory: 53440kb

input:

1000 1000
411 936 467 652 654 870 544 32 4 510 859 984 38 130 45 311 103 127 539 741 78 540 663 707 537 614 647 480 325 943 716 583 70 754 565 871 318 473 705 161 934 704 960 454 30 687 571 519 387 531 584 547 715 373 919 140 187 513 999 826 338 825 394 894 779 216 244 368 823 728 104 611 40 900 467...

output:

61802460

result:

ok single line: '61802460'

Test #24:

score: 0
Accepted
time: 1960ms
memory: 53440kb

input:

1000 1000
551 193 944 906 622 45 236 187 186 950 603 74 279 941 962 226 557 41 588 681 856 753 46 564 553 836 508 88 3 169 283 170 503 863 165 600 96 711 112 966 344 485 119 643 10 498 815 945 557 453 931 536 239 373 961 27 808 368 507 233 147 864 671 630 144 1 368 967 149 277 186 434 552 480 601 34...

output:

849139143

result:

ok single line: '849139143'

Test #25:

score: 0
Accepted
time: 1962ms
memory: 53240kb

input:

1000 1000
189 942 273 771 441 891 200 358 733 973 938 345 979 806 417 289 424 503 526 823 997 89 684 543 394 691 283 833 910 336 710 148 504 86 877 790 617 127 844 653 791 339 186 529 260 741 331 95 637 794 983 200 804 61 664 95 375 614 432 151 190 278 17 619 728 252 739 660 255 323 353 183 983 706 ...

output:

15494064

result:

ok single line: '15494064'

Test #26:

score: 0
Accepted
time: 1946ms
memory: 53280kb

input:

1000 1000
411 789 753 186 495 203 417 324 490 424 195 480 314 23 663 218 12 747 124 390 134 38 218 536 291 840 174 908 474 767 313 167 575 9 857 427 313 27 959 935 258 70 472 957 747 228 205 939 293 303 626 802 712 283 658 346 208 383 889 204 99 640 801 966 828 742 534 11 259 734 226 129 843 350 50 ...

output:

81830009

result:

ok single line: '81830009'

Extra Test:

score: 0
Extra Test Passed