QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#290685#6139. 卡牌游戏MoRanSky100 ✓269ms42864kbC++231.4kb2023-12-25 06:26:352023-12-25 06:26:36

Judging History

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

  • [2023-12-25 06:26:36]
  • 评测
  • 测评结果:100
  • 用时:269ms
  • 内存:42864kb
  • [2023-12-25 06:26:35]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;

const int N = 1e6 + 5;

int n, m, a[N], b[N], tot, ans = 2e9;

struct Op{
	int x, op, id;
	bool operator < (const Op &b) const {
		return x < b.x;
	}
} e[N << 1];

int s = 0, need = 0, v1[N], v2[N];

void inline ins(int i) {
	int x = e[i].x, op = e[i].op, t = e[i].id;
	if (op == 1) {
		v1[t] = 1;
		if (!v2[t]) s++;
		else need--;
	} else if (op == 2) {
		v2[t] = 1;
		if (!v1[t]) s++, need++;
	}
}

void inline del(int i) {
	int x = e[i].x, op = e[i].op, t = e[i].id;
	if (op == 1) {
		v1[t] = 0;
		if (!v2[t]) s--;
		else need++;
	} else if (op == 2) {
		v2[t] = 0;
		if (!v1[t]) s--, need--;
	}
}

bool inline check() {
	return s == n && need <= m;
}

bool inline ok(int i) {
	del(i);
	if (check()) return true;
	else {
		ins(i);
		return false;
	}
}

int main() {
	//freopen("card.in", "r", stdin);
	//freopen("card.out", "w", stdout);
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", a + i), e[++tot] = (Op) { a[i], 1, i };
	for (int i = 1; i <= n; i++) scanf("%d", b + i), e[++tot] = (Op) { b[i], 2, i };
	sort(e + 1, e + 1 + tot);
	for (int i = 1, j = 1; i <= tot; i++) {
		ins(i);
		while (j < i && ok(j)) j++;
		if (check()) ans = min(ans, e[i].x - e[j].x);	
	}
	printf("%d\n", ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 0ms
memory: 8020kb

input:

10 5
180 193 194 225 260 273 276 314 316 322
271 1 255 234 196 500 250 240 218 205

output:

80

result:

ok 1 number(s): "80"

Test #2:

score: 10
Accepted
time: 0ms
memory: 7988kb

input:

10 5
175 177 181 206 207 256 283 309 317 323
300 275 259 1 216 273 266 500 236 228

output:

103

result:

ok 1 number(s): "103"

Test #3:

score: 10
Accepted
time: 1ms
memory: 8012kb

input:

500 387
3510 3514 3515 3518 3519 3524 3526 3530 3531 3536 3541 3545 3546 3556 3558 3559 3560 3561 3565 3567 3570 3573 3576 3577 3579 3580 3582 3586 3589 3593 3594 3599 3602 3603 3607 3611 3613 3614 3615 3617 3619 3621 3622 3624 3625 3627 3632 3636 3642 3643 3645 3646 3649 3651 3654 3655 3659 3660 36...

output:

1737

result:

ok 1 number(s): "1737"

Test #4:

score: 10
Accepted
time: 0ms
memory: 7876kb

input:

500 270
3501 3505 3511 3517 3529 3536 3537 3538 3541 3544 3545 3547 3550 3551 3554 3557 3558 3562 3567 3569 3571 3577 3578 3580 3587 3588 3591 3592 3594 3597 3602 3604 3606 3607 3608 3612 3613 3617 3618 3619 3621 3625 3626 3627 3628 3629 3635 3637 3640 3644 3645 3650 3651 3655 3656 3657 3659 3662 36...

output:

2190

result:

ok 1 number(s): "2190"

Test #5:

score: 10
Accepted
time: 134ms
memory: 28236kb

input:

500000 1000
350000022 350000647 350000754 350000903 350001445 350001446 350001570 350002086 350002160 350002612 350003198 350003367 350003475 350003535 350003860 350004038 350004288 350004554 350004981 350005570 350005900 350006188 350006248 350006338 350006588 350006924 350007501 350007748 35000864...

output:

299698746

result:

ok 1 number(s): "299698746"

Test #6:

score: 10
Accepted
time: 123ms
memory: 29616kb

input:

500000 1000
350000710 350000827 350001345 350001674 350002235 350002823 350002847 350003025 350003422 350003460 350004170 350004399 350005178 350005324 350005342 350005660 350006003 350006430 350006525 350006643 350006950 350007085 350007169 350007346 350007615 350007658 350007713 350008148 35000826...

output:

299703811

result:

ok 1 number(s): "299703811"

Test #7:

score: 10
Accepted
time: 25ms
memory: 11244kb

input:

100000 68773
350000814 350001419 350001900 350002529 350002673 350003306 350003726 350004742 350005509 350006284 350006558 350008691 350009505 350009709 350011601 350012101 350012274 350012337 350015828 350022545 350027002 350027565 350032727 350034972 350035219 350036143 350040234 350045735 3500472...

output:

196257709

result:

ok 1 number(s): "196257709"

Test #8:

score: 10
Accepted
time: 100ms
memory: 26944kb

input:

400000 235635
350000178 350001601 350001625 350001697 350001712 350001754 350001837 350003581 350004046 350004390 350004940 350005109 350005359 350005520 350005832 350005902 350006399 350007213 350007293 350008091 350008353 350008566 350009052 350009120 350010917 350011022 350011346 350011405 350012...

output:

211641167

result:

ok 1 number(s): "211641167"

Test #9:

score: 10
Accepted
time: 183ms
memory: 35592kb

input:

700000 429596
350000035 350000298 350000537 350000675 350000863 350001159 350001767 350001901 350001936 350002441 350002732 350002998 350003005 350003276 350003947 350004329 350004601 350005037 350005069 350006088 350006214 350006363 350006767 350007186 350007379 350007731 350008076 350008467 350008...

output:

207938344

result:

ok 1 number(s): "207938344"

Test #10:

score: 10
Accepted
time: 269ms
memory: 42864kb

input:

1000000 651322
350000041 350000169 350000312 350000951 350001280 350001402 350001559 350001598 350001840 350002340 350002385 350002418 350002581 350002689 350002866 350003018 350003071 350003205 350003333 350003506 350003613 350003776 350003826 350004028 350004086 350004243 350004343 350004399 35000...

output:

202185410

result:

ok 1 number(s): "202185410"

Extra Test:

score: 0
Extra Test Passed