QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#375228#7130. Long binary sequenceI_Love_Sonechka#AC ✓49ms19028kbC++142.0kb2024-04-03 00:44:462024-04-03 00:44:47

Judging History

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

  • [2024-04-03 00:44:47]
  • 评测
  • 测评结果:AC
  • 用时:49ms
  • 内存:19028kb
  • [2024-04-03 00:44:46]
  • 提交

answer

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

// c++ short types
#define Int long long
#define vt vector
typedef unsigned long long ull;

const int mod = 1e9 + 123, base = 517;

void solver() {
	int n, m; cin >> n >> m;
	vt<int> a;
	int prev = 0;
	for(int i = 0; i < m; ++i) {
		int x; cin >> x;
		a.push_back(x-prev-1);
		prev = x;
	}
	a.push_back(n-prev);
	vt<pair<int, ull>> pw(m+2, {1, 1});
	for(int i = 1; i < pw.size(); ++i) {
		pw[i].first = pw[i-1].first * 1ll * base % mod;
		pw[i].second = pw[i-1].second * base;
	}
	vt<vt<pair<int, ull>>> b(m+2, vt<pair<int, ull>>(m+2, {0, 0}));
	for(int i = 0; i < a.size(); ++i) {
		for(int j = i; j < a.size(); ++j) {
			if(i != j) {
				b[i][j] = b[i][j-1];
			}
			b[i][j].first = (b[i][j].first + pw[j-i].first * 1ll * a[j] % mod) % mod;
			b[i][j].second = b[i][j].second + pw[j-i].second * a[j];
		}
	}
	Int res = *max_element(a.begin(), a.end());
	auto Calc = [](vt<pair<int, int>> &z) {
		z.push_back({-1, 0});
		sort(z.rbegin(), z.rend());
		Int res = 0, maxb = z[0].second;
		for(int i = 0; i < z.size(); ++i) {
			if(i) {
				res += (maxb+1) *  (z[i-1].first - z[i].first);
			}
			maxb = max(maxb, (Int)z[i].second);
		}
		return res;
	};
	{
		vt<pair<int, int>> z;
		for(int i = 0; i + 1 < a.size(); ++i) {
			z.push_back({a[i], a[i+1]});
		}
		res += Calc(z);
	}
	for(int le = 0; le < m + 2; ++le) {
		vt<pair<pair<int, ull>, pair<int, int>>> v;
		for(int i = 1; i + le + 1 < a.size(); ++i) {
			v.push_back({b[i][i+le], {a[i-1], a[i+le+1]}});
		}
		sort(v.begin(), v.end());
		for(int i = 0; i < v.size(); ++i) {
			int j = i; 
			vt<pair<int, int>> z;
			while(j < v.size() && v[j].first == v[i].first) {
				z.push_back(v[j].second);
				++j;
			}
			// (ai, bi)
			reverse(z.begin(), z.end());
			res += Calc(z);
			i = j -1;
		}
	}
	cout << res << "\n";
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int tt = 1;
	for(int t = 0; t < tt; ++t) {
    solver();
	}
	return 0;
}

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

詳細信息

Test #1:

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

input:

3 2
1 3

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

1000000000 1
1

output:

1999999999

result:

ok 1 number(s): "1999999999"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

98 10
13 19 25 32 36 48 61 73 81 93

output:

3653

result:

ok 1 number(s): "3653"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

89 10
4 5 29 32 39 56 57 59 84 87

output:

2996

result:

ok 1 number(s): "2996"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

95 10
3 22 30 36 42 47 55 83 86 88

output:

3493

result:

ok 1 number(s): "3493"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

97 10
3 22 30 34 46 55 72 80 88 90

output:

3616

result:

ok 1 number(s): "3616"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

94 10
3 29 35 36 40 42 56 65 84 93

output:

3335

result:

ok 1 number(s): "3335"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

99 10
6 9 17 26 30 56 67 83 84 87

output:

3905

result:

ok 1 number(s): "3905"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

87 10
11 12 15 34 47 53 64 73 83 86

output:

2960

result:

ok 1 number(s): "2960"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

100 10
19 22 38 43 49 55 60 67 78 87

output:

4026

result:

ok 1 number(s): "4026"

Test #11:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

90 10
8 14 28 44 53 54 59 63 77 82

output:

3180

result:

ok 1 number(s): "3180"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

100 10
8 9 18 20 30 50 64 67 82 87

output:

4042

result:

ok 1 number(s): "4042"

Test #13:

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

input:

982 100
17 20 29 41 51 55 57 59 96 100 142 159 163 167 175 183 192 195 198 200 245 248 264 296 319 327 332 366 386 400 424 436 441 469 475 491 494 500 516 522 529 534 535 552 553 557 563 582 585 588 590 606 618 628 633 653 656 662 679 681 683 689 696 707 716 718 722 725 738 750 756 771 779 780 786 7...

output:

462106

result:

ok 1 number(s): "462106"

Test #14:

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

input:

970 100
29 31 45 63 67 68 114 125 132 136 143 147 151 157 174 176 178 187 200 209 214 234 237 239 254 256 259 266 268 275 279 280 281 293 298 313 316 317 321 322 324 340 342 359 370 375 382 393 396 407 415 426 429 436 447 457 470 480 484 492 499 503 506 508 534 536 550 560 561 566 573 593 623 642 64...

output:

451179

result:

ok 1 number(s): "451179"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3748kb

input:

903 100
15 17 19 27 65 66 79 80 87 96 101 106 121 127 136 143 147 155 161 166 168 171 175 190 193 196 209 222 243 246 250 261 271 282 283 284 292 293 302 304 306 308 329 332 343 352 359 361 366 391 399 418 421 428 447 454 459 463 474 483 486 515 528 530 533 580 591 596 644 656 658 661 668 671 677 68...

output:

390229

result:

ok 1 number(s): "390229"

Test #16:

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

input:

965 100
1 4 10 15 18 34 43 61 76 80 89 120 126 129 130 133 135 139 145 156 163 167 180 187 198 205 206 226 228 232 233 254 262 265 305 307 312 331 339 347 356 362 405 416 421 427 429 442 447 472 491 501 504 534 543 575 581 582 596 604 619 620 636 646 652 661 686 694 703 704 709 720 738 745 747 755 7...

output:

446714

result:

ok 1 number(s): "446714"

Test #17:

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

input:

902 100
3 8 12 13 15 17 22 33 41 52 56 59 72 92 96 120 121 138 140 146 150 154 159 174 176 190 196 209 215 226 228 243 248 253 266 277 283 289 300 310 315 330 334 339 343 353 355 368 375 381 391 407 412 452 455 459 465 475 480 488 495 500 509 513 540 544 553 568 573 588 598 606 624 628 629 661 663 6...

output:

390092

result:

ok 1 number(s): "390092"

Test #18:

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

input:

970 100
10 17 18 62 83 89 97 111 113 114 136 148 178 182 224 228 246 259 271 278 285 289 309 311 328 335 342 346 349 354 356 365 388 389 394 402 408 435 451 466 467 472 473 486 496 500 509 512 515 534 562 573 593 599 601 607 613 615 635 639 640 646 650 658 661 667 668 675 678 682 684 685 692 703 710...

output:

451126

result:

ok 1 number(s): "451126"

Test #19:

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

input:

821 100
10 13 17 21 25 31 32 37 50 58 59 85 97 105 113 118 119 127 137 139 146 156 157 165 167 168 169 194 196 200 205 207 213 217 221 222 251 257 260 267 304 306 313 325 338 342 344 360 363 396 398 429 437 438 444 463 471 472 474 499 507 519 522 548 555 558 562 565 569 572 587 597 606 609 614 616 6...

output:

323238

result:

ok 1 number(s): "323238"

Test #20:

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

input:

983 100
12 21 30 35 40 55 61 79 108 110 112 122 125 132 140 146 149 153 155 166 168 202 207 211 240 242 245 247 268 270 274 276 277 280 304 306 309 312 319 321 332 334 344 348 365 370 376 385 397 402 429 435 437 447 454 463 467 477 488 504 507 526 541 564 574 579 597 626 629 632 685 692 708 711 723 ...

output:

463376

result:

ok 1 number(s): "463376"

Test #21:

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

input:

821 100
3 11 33 41 47 56 75 86 107 110 113 115 127 130 132 135 137 153 159 165 166 167 168 170 175 181 188 196 197 219 225 237 254 257 259 273 278 280 284 294 299 311 314 319 323 329 348 351 352 360 366 369 377 379 382 385 388 408 430 436 453 462 475 497 501 516 535 553 555 560 563 567 579 584 596 6...

output:

322845

result:

ok 1 number(s): "322845"

Test #22:

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

input:

993 100
2 5 11 16 20 36 57 74 100 108 138 143 144 151 153 158 178 182 186 189 226 244 245 254 260 267 301 316 327 340 346 351 360 365 378 382 405 416 427 429 440 448 460 462 477 481 512 524 530 536 540 548 575 577 580 582 599 601 605 609 619 635 650 651 660 677 690 700 703 710 725 729 736 743 748 75...

output:

473213

result:

ok 1 number(s): "473213"

Test #23:

score: 0
Accepted
time: 48ms
memory: 19028kb

input:

989785635 1000
383594 786775 876419 913740 1014658 2369883 2671618 2883124 3086152 4892871 5509426 5777768 9055248 11046388 11541047 13843544 16868234 17040846 17248876 18202253 18478710 19149771 21146093 22307732 23096568 23399339 23908488 24677933 24691812 24719261 29462266 29931726 31079636 32452...

output:

487821217190004145

result:

ok 1 number(s): "487821217190004145"

Test #24:

score: 0
Accepted
time: 44ms
memory: 18984kb

input:

972920486 1000
1354351 3156141 3555730 3760888 4339651 4887677 12018973 12676080 13611581 13920278 14933321 14940081 15921923 16367317 17143185 17734406 18234891 18465228 19182308 19514305 20920855 21003874 23617750 23800679 25684666 25715921 27089424 27393299 28637716 30114469 30699948 31446859 315...

output:

471442102279015419

result:

ok 1 number(s): "471442102279015419"

Test #25:

score: 0
Accepted
time: 44ms
memory: 18980kb

input:

896649241 1000
5675 3941061 4116512 5361180 8043341 8519863 9250820 11683106 12338559 13796216 15474552 17134595 19138655 19790296 20398187 21484177 21507959 21857282 23321811 24440022 25671951 26864087 30390997 30986092 31575477 31966453 32311856 32338816 33643909 34023079 38703444 39442948 3964475...

output:

400393613189766409

result:

ok 1 number(s): "400393613189766409"

Test #26:

score: 0
Accepted
time: 44ms
memory: 18896kb

input:

919722501 1000
2703738 3205173 3328703 3597753 5258727 5496586 5961319 6625131 7519744 8754373 9003902 10332142 11197132 11847966 12625100 13582801 16040035 18439645 18679431 19049649 21712005 22201076 22613934 23061638 26137263 26618906 29689248 29703546 32921086 33058802 34216153 35946027 36077496...

output:

421306773141875874

result:

ok 1 number(s): "421306773141875874"

Test #27:

score: 0
Accepted
time: 44ms
memory: 18888kb

input:

982848416 1000
330892 668932 986754 3139506 4096862 5780515 6126263 6285046 8703237 8840522 13599522 14797797 17508801 18534499 18775083 22118324 22281443 22356718 23212865 24046684 24275216 25956303 26249822 26468129 26932407 27173365 27948097 27985057 28241698 28338201 29422536 29773613 30116112 3...

output:

481101090749013703

result:

ok 1 number(s): "481101090749013703"

Test #28:

score: 0
Accepted
time: 49ms
memory: 18976kb

input:

923495175 1000
43019 122707 322305 656012 1038246 1462643 3687693 4242807 5172382 5756522 6133733 6329145 8811299 8944199 10143915 10254880 10456357 10803106 13188960 13227275 13240181 14243765 15214066 16150999 16427506 18593621 19323938 20577057 24727254 25748363 29684242 32120443 32869774 3288155...

output:

424689501788434052

result:

ok 1 number(s): "424689501788434052"

Test #29:

score: 0
Accepted
time: 49ms
memory: 18968kb

input:

958592107 1000
33802 52896 1041792 2886583 3050289 3152357 3772152 4477171 4710845 5771112 6332091 7596939 8498747 9756972 10295039 10821177 12631146 12840028 12934859 13024580 14165220 15272758 16012182 17712471 19901979 19961626 20446092 20997007 21193225 23820558 23894862 24003906 24022363 242506...

output:

457667935624130423

result:

ok 1 number(s): "457667935624130423"

Test #30:

score: 0
Accepted
time: 44ms
memory: 18876kb

input:

941392464 1000
308935 703619 2887430 3513609 6761707 8485367 8608650 9162900 10055231 11804454 12039681 12060140 12870862 13373574 14079290 15665948 16395276 16595177 20832124 22787689 25313628 25719650 26211676 26711659 27276774 27612891 29853711 31818713 32110507 32410347 34828346 38770785 3884162...

output:

441341385300569766

result:

ok 1 number(s): "441341385300569766"

Test #31:

score: 0
Accepted
time: 44ms
memory: 18960kb

input:

968826215 1000
4451003 8527520 12282515 14959924 15258049 15512732 15713897 16573488 18858091 19156399 19431199 20629384 21259851 22029058 22538022 23012241 23476679 25504747 26528626 26766255 27820256 30155955 31409772 31890089 32986906 33196534 33224851 33995366 34338584 36429863 38965544 39093545...

output:

467460118800772190

result:

ok 1 number(s): "467460118800772190"

Test #32:

score: 0
Accepted
time: 40ms
memory: 18936kb

input:

946870820 1000
66707 1134938 1243738 1372684 3036081 3238812 3946372 5622041 7153026 7506242 7939632 8601417 10211368 10658302 12363946 12613174 14212549 14435583 16800869 17195808 17631722 19849341 20612825 26873454 27296165 27487389 28093606 28204860 28331909 28454529 28760846 29143408 29890456 30...

output:

446552245088090341

result:

ok 1 number(s): "446552245088090341"