QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293436#4897. 音符大师zyc07041915 35ms28076kbC++141.9kb2023-12-29 09:46:292023-12-29 09:46:29

Judging History

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

  • [2023-12-29 09:46:29]
  • 评测
  • 测评结果:15
  • 用时:35ms
  • 内存:28076kb
  • [2023-12-29 09:46:29]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5e4 + 10;
const int B = 12000;
const int M = 30000;
const int mod = 2999997;
const int W = 3000000;

mt19937 rnd(time(0));
int key = rnd() % mod;
struct Hash {
	struct node {
		int x, y;
		ll val;
		node(int a = 0, int b = 0, ll c = 0) {x = a; y = b; val = c;}
	}q[M];
	struct edge {
		int to, nxt;
	}e[M];
	int link[W], tot, cnt, num;
	
	int f(int x, int y) {
		x = (x ^ key) % mod; y = 1ll * (y + key) * key % mod;
		return 1ll * (3ll * x % mod * key) % mod * (y ^ (7ll * key % mod)) % mod + 1;
	}
	
	void ins(int x, int y, ll val) {
		int id = f(x, y);
		for (int i = link[id]; i; i = e[i].nxt) {
			int to = e[i].to;
			if (q[to].x == x && q[to].y == y) return q[to].val = min(q[to].val, val), void();
		}
		q[++cnt] = node(x, y, val);
		e[++tot].nxt = link[id]; e[tot].to = cnt; link[id] = tot;
	}
	
	void init() {
		for (int i = 1; i <= cnt; ++i) link[f(q[i].x, q[i].y)] = 0;
		tot = 0; num = cnt; cnt = 0;
		if (num <= B) return;
		nth_element(q + 1, q + 1 + B, q + 1 + num, [&](node xx, node yy) {return xx.val < yy.val;});
		num = B;
	}
}H[2];
int n, L, cnt, opt;

int main() {
	scanf("%d%d", &n, &L);
	H[opt].ins(0, 0, 0);
	for (int i = 1; i <= n; ++i) {
		int p, x, y; ll val;
		scanf("%d", &p); H[opt].init();
		for (int j = 1; j <= H[opt].num; ++j) {
			x = H[opt].q[j].x;
			y = H[opt].q[j].y;
			val = H[opt].q[j].val;
			if ((x <= p && p <= x + L) || (y <= p && p <= y + L)) H[opt ^ 1].ins(x, y, val);
			else if (p < x) H[opt ^ 1].ins(p, y, val + x - p);
			else if (y + L < p) H[opt ^ 1].ins(x, p - L, val + p - y - L);
			else {
				H[opt ^ 1].ins(p - L, y, val + p - x - L);
				H[opt ^ 1].ins(x, p, val + y - p);
			}
		}
		opt ^= 1;
	}
	ll ans = 1e18;
	for (int i = 1; i <= H[opt].cnt; ++i) ans = min(ans, H[opt].q[i].val);
	return printf("%lld\n", ans), 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 15
Accepted

Test #1:

score: 15
Accepted
time: 0ms
memory: 12476kb

input:

200 20
78 30 163 87 97 53 96 76 81 138 156 200 124 93 173 119 115 93 150 99 22 80 88 131 61 126 47 103 143 142 129 186 89 105 101 143 178 110 13 77 79 178 21 108 200 146 87 105 54 61 136 69 161 195 13 105 18 151 25 191 30 35 90 110 17 98 181 58 120 102 139 71 59 24 72 84 33 12 28 82 23 80 128 96 115...

output:

3669

result:

ok single line: '3669'

Test #2:

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

input:

200 48
94 162 22 10 28 87 165 108 7 143 94 185 98 181 159 0 170 15 112 29 137 119 108 109 72 22 132 96 105 117 189 49 122 76 154 142 13 184 158 198 162 75 24 192 150 166 170 48 124 154 94 165 50 38 170 192 107 11 19 188 111 36 23 28 165 178 91 184 188 9 65 26 6 78 51 58 72 57 41 92 90 0 81 191 133 1...

output:

1665

result:

ok single line: '1665'

Test #3:

score: 0
Accepted
time: 2ms
memory: 12204kb

input:

200 6
129 31 73 103 93 174 111 45 59 173 87 61 41 146 86 60 84 95 126 149 164 190 42 10 113 153 51 33 7 191 64 165 200 139 20 81 140 196 40 155 166 78 77 162 150 59 93 174 137 62 32 42 155 42 176 185 136 101 52 178 68 168 160 141 27 141 182 197 29 43 52 3 59 101 27 148 129 183 160 178 40 83 26 37 61...

output:

5261

result:

ok single line: '5261'

Test #4:

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

input:

200 32
193 9 97 35 133 131 163 131 28 128 135 28 20 149 34 92 148 171 98 87 88 121 195 67 28 134 61 42 120 7 31 179 194 155 69 32 9 126 28 180 144 98 101 188 38 150 22 114 20 32 99 15 95 125 147 99 186 188 178 155 44 57 5 157 154 173 164 111 175 137 52 41 22 80 113 172 93 151 33 64 37 187 40 70 20 3...

output:

2919

result:

ok single line: '2919'

Test #5:

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

input:

200 45
193 39 78 169 128 182 91 182 21 15 37 177 144 184 193 79 85 126 35 135 29 62 176 25 164 42 150 174 170 110 113 147 15 46 158 122 195 139 188 170 28 107 45 147 46 171 0 180 67 66 194 54 9 6 33 115 183 119 132 83 165 56 124 178 90 68 30 185 60 105 31 139 36 10 112 13 70 168 38 5 194 42 170 37 7...

output:

1880

result:

ok single line: '1880'

Test #6:

score: 0
Accepted
time: 3ms
memory: 8868kb

input:

200 47
196 61 44 155 195 196 174 199 28 55 41 70 50 43 129 176 143 172 196 33 19 58 100 136 125 94 31 53 71 69 96 62 41 163 1 43 62 63 183 179 175 107 65 198 40 198 172 43 14 44 0 190 197 171 128 187 20 34 84 183 183 146 128 46 42 87 122 168 183 107 105 165 7 29 8 4 7 164 177 161 50 0 12 70 68 123 1...

output:

1473

result:

ok single line: '1473'

Test #7:

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

input:

200 14
191 73 156 161 162 165 168 165 174 44 41 34 60 18 18 18 112 166 71 71 10 20 19 29 137 147 148 69 37 40 42 32 178 118 183 193 183 171 93 100 27 29 37 28 22 14 26 186 147 161 158 8 10 12 6 3 190 107 127 127 124 115 122 159 155 157 44 63 114 114 114 116 124 76 151 137 77 9 198 5 5 17 185 179 178...

output:

2484

result:

ok single line: '2484'

Test #8:

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

input:

200 8
2 0 7 13 9 147 144 136 100 108 115 163 170 168 64 64 62 61 130 127 122 77 3 0 78 84 61 53 59 60 62 54 55 48 119 76 13 8 2 0 197 199 195 32 29 36 35 35 28 6 165 171 99 76 69 76 68 186 179 137 145 149 144 144 5 22 132 139 5 9 14 20 21 13 7 51 84 137 58 66 71 162 157 150 150 153 159 145 149 147 1...

output:

2616

result:

ok single line: '2616'

Test #9:

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

input:

200 37
195 162 181 5 182 151 176 158 121 115 168 167 147 76 92 127 184 150 192 21 58 34 14 21 34 81 91 95 34 53 61 45 192 182 194 193 171 188 10 59 31 29 170 44 74 37 4 18 195 28 6 182 184 73 101 114 10 175 195 21 21 6 178 7 196 146 163 175 182 186 160 123 148 157 187 171 134 179 179 194 194 163 169...

output:

1901

result:

ok single line: '1901'

Test #10:

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

input:

200 7
24 18 24 25 22 26 12 7 1 56 55 52 53 125 60 64 68 196 196 199 197 190 191 182 181 3 186 61 119 120 142 141 142 47 188 188 190 183 187 154 147 24 18 11 4 200 200 200 68 73 177 173 173 99 23 27 50 52 54 56 55 60 65 69 74 148 153 105 103 109 103 103 103 109 102 97 94 29 29 26 25 37 177 184 115 14...

output:

2257

result:

ok single line: '2257'

Test #11:

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

input:

192 19
99 102 103 96 95 106 93 92 109 90 89 88 87 86 85 116 117 118 81 80 121 78 123 76 125 126 127 128 129 130 69 68 133 134 135 136 63 138 139 60 141 58 57 144 55 146 147 148 149 50 151 152 153 46 155 44 43 158 41 40 39 38 163 164 165 34 167 168 169 30 29 28 173 174 25 24 23 22 21 180 19 18 17 16 ...

output:

457

result:

ok single line: '457'

Test #12:

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

input:

199 49
101 98 97 96 95 94 107 108 109 90 111 88 87 114 115 116 83 118 119 80 79 78 77 76 75 126 73 72 129 130 69 132 133 66 135 64 137 138 61 60 59 58 57 56 145 146 53 148 149 50 49 152 47 154 155 44 157 158 159 40 161 38 163 164 35 166 33 168 31 170 171 172 27 174 175 176 177 178 21 20 19 18 183 16...

output:

293

result:

ok single line: '293'

Test #13:

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

input:

194 45
100 101 99 102 98 103 97 104 96 105 95 106 94 107 93 108 92 109 91 110 90 111 89 112 88 113 87 114 86 115 85 116 84 117 83 118 82 119 81 120 80 121 79 122 78 123 77 124 76 125 75 126 74 127 73 128 72 129 71 130 70 131 69 132 68 133 67 134 66 135 65 136 64 137 63 138 62 139 61 140 60 141 59 14...

output:

212

result:

ok single line: '212'

Test #14:

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

input:

194 22
100 101 99 102 98 103 97 104 96 105 95 106 94 107 93 108 92 109 91 110 90 111 89 112 88 113 87 114 86 115 85 116 84 117 83 118 82 119 81 120 80 121 79 122 78 123 77 124 76 125 75 126 74 127 73 128 72 129 71 130 70 131 69 132 68 133 67 134 66 135 65 136 64 137 63 138 62 139 61 140 60 141 59 14...

output:

303

result:

ok single line: '303'

Test #15:

score: 0
Accepted
time: 4ms
memory: 25404kb

input:

199 28
1 199 2 198 3 197 4 196 5 195 6 194 7 193 8 192 9 191 10 190 11 189 12 188 13 187 14 186 15 185 16 184 17 183 18 182 19 181 20 180 21 179 22 178 23 177 24 176 25 175 26 174 27 173 28 172 29 171 30 170 31 169 32 168 33 167 34 166 35 165 36 164 37 163 38 162 39 161 40 160 41 159 42 158 43 157 4...

output:

313

result:

ok single line: '313'

Test #16:

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

input:

193 42
4 196 5 195 6 194 7 193 8 192 9 191 10 190 11 189 12 188 13 187 14 186 15 185 16 184 17 183 18 182 19 181 20 180 21 179 22 178 23 177 24 176 25 175 26 174 27 173 28 172 29 171 30 170 31 169 32 168 33 167 34 166 35 165 36 164 37 163 38 162 39 161 40 160 41 159 42 158 43 157 44 156 45 155 46 15...

output:

265

result:

ok single line: '265'

Test #17:

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

input:

197 39
96 95 106 107 92 91 90 89 88 87 86 115 84 83 82 81 80 79 78 77 124 125 74 127 128 129 70 69 68 67 66 135 136 63 138 61 60 141 58 143 56 55 54 147 52 51 150 151 48 153 46 45 156 43 42 159 40 161 38 37 36 35 166 33 168 31 170 171 28 27 26 25 24 23 22 21 180 19 182 183 184 185 186 187 188 11 10 ...

output:

347

result:

ok single line: '347'

Test #18:

score: 0
Accepted
time: 3ms
memory: 13872kb

input:

198 24
103 96 95 94 93 108 91 110 89 112 113 114 115 116 117 82 81 120 79 78 123 76 75 126 73 128 129 70 131 68 67 66 65 136 137 138 61 140 141 58 57 56 55 54 53 148 149 50 49 152 153 46 45 156 157 42 159 160 161 162 163 36 35 166 167 32 169 30 171 28 27 26 25 176 23 22 21 20 181 18 183 184 185 14 1...

output:

439

result:

ok single line: '439'

Subtask #2:

score: 0
Time Limit Exceeded

Test #19:

score: 15
Accepted
time: 22ms
memory: 27568kb

input:

50000 0
957304147 455870042 888520405 388924006 685268286 213595280 898496267 50362797 310595209 105517171 706682592 663787741 927429771 306122736 1352192 453945549 31881610 943782347 779421515 543589796 209926777 908434673 845417119 374441290 190474943 606994057 30091060 491598457 644246786 4649716...

output:

7861788079227

result:

ok single line: '7861788079227'

Test #20:

score: 0
Accepted
time: 22ms
memory: 27488kb

input:

50000 0
267539818 976941407 232914453 134486565 946077774 327303661 383860856 427463180 82433525 829152030 323047687 114009885 572336732 324540200 312372486 904267355 354174716 897077585 726797234 14815480 56504568 128226636 908533574 690241784 234432089 60842581 4158447 140784062 814696061 27580609...

output:

7502844748010

result:

ok single line: '7502844748010'

Test #21:

score: 0
Accepted
time: 32ms
memory: 27844kb

input:

50000 0
113234313 300322176 223748251 154992665 988783374 705920968 587653430 735106433 339878986 23782050 772071399 43924374 333487655 112104185 388912725 30645653 230657785 50181507 210382459 974636263 84812430 683840330 470879024 352138490 544953829 857016921 83527213 679251552 204113040 48552509...

output:

7819216642612

result:

ok single line: '7819216642612'

Test #22:

score: 0
Accepted
time: 25ms
memory: 27304kb

input:

50000 0
57573834 735491176 585967317 50750966 13561867 538400010 923336660 411978534 229545007 608845964 778611980 433080482 340855878 525841885 436793984 121792438 646117967 157139578 341644163 71379300 980382262 841426801 263042095 570909388 241669384 780525526 306815843 529038526 677693926 272888...

output:

7502087871392

result:

ok single line: '7502087871392'

Test #23:

score: 0
Accepted
time: 22ms
memory: 27736kb

input:

50000 0
150529956 908563845 724316344 71839499 520290302 12371329 763161706 965762834 605485868 377855450 364159073 557572417 13573314 8085996 723464069 322060474 374561435 448408270 121729850 91335553 69989524 231531526 901985946 472906330 960997677 246590568 401537295 540808342 30457662 978645485 ...

output:

7655855679050

result:

ok single line: '7655855679050'

Test #24:

score: 0
Accepted
time: 21ms
memory: 27436kb

input:

50000 0
940144100 18386479 769788658 44738457 90257879 879207970 925016558 964597036 662771443 441833534 638630926 257398005 693370314 852807331 472327316 858562055 874978007 530679568 947674579 7081350 647463115 399061769 81471568 897044511 672282388 395480185 381093973 103836241 52060856 136053749...

output:

7329741440393

result:

ok single line: '7329741440393'

Test #25:

score: 0
Accepted
time: 23ms
memory: 27836kb

input:

50000 0
595877781 416920133 504115297 682623073 942495777 808743152 122852578 564363701 980818902 501483584 374724004 69557753 835258645 860520007 102814074 680949932 29792102 646922045 695269515 161539625 468996996 528287965 284414170 145379630 414176299 532680752 96308272 806611720 849878782 97734...

output:

7372386712114

result:

ok single line: '7372386712114'

Test #26:

score: 0
Accepted
time: 21ms
memory: 27116kb

input:

50000 0
236037002 215233133 41019240 229757515 806834959 849843304 862557844 39545138 297402862 7293515 880125105 285706647 152887583 198537021 740552834 3427605 366976152 641734017 106888137 154277089 259614856 518826105 796155721 132034997 420344028 702041117 117477828 821050418 113096425 2869065 ...

output:

7508382287165

result:

ok single line: '7508382287165'

Test #27:

score: 0
Accepted
time: 35ms
memory: 27952kb

input:

50000 0
428263671 324606118 736973623 961066097 320407929 663897387 328110400 789178775 344241539 34611323 77458169 730418405 89677130 456628708 735813218 665313790 99553725 408359166 161580926 95603740 537817168 587203140 239173276 980655467 73440384 209550435 242679387 923020102 447641965 71570611...

output:

7241590054407

result:

ok single line: '7241590054407'

Test #28:

score: 0
Accepted
time: 25ms
memory: 27928kb

input:

50000 0
848511669 673688847 134042037 382760566 86940474 283461772 923214109 543686174 579545679 713904091 366348707 242716930 5641588 704870794 542778347 296428822 959149832 495183306 649986132 551497587 550623110 591035272 204338017 214181048 891861232 524406707 448388519 594832891 610827442 93698...

output:

7606261035748

result:

ok single line: '7606261035748'

Test #29:

score: 0
Accepted
time: 22ms
memory: 27644kb

input:

50000 0
532965906 613164218 854565797 576587516 227406875 115434558 767691663 854474298 982611179 969491137 234543738 69267955 646968047 897911688 721008706 422527377 387136261 762884658 51918347 448273062 574144173 857719871 888425078 575352222 730868624 568669670 590036983 778842602 259437307 7201...

output:

7641479018806

result:

ok single line: '7641479018806'

Test #30:

score: 0
Accepted
time: 25ms
memory: 27448kb

input:

50000 0
950114012 924063984 78459732 2585137 167568618 422620546 817141675 939136111 912071559 28108367 138440975 401623398 614543476 413859636 583198666 7145092 692094019 896479223 265275914 14852033 553761091 831725889 256534067 178236755 434539705 610839223 807151106 140182765 324816595 576215181...

output:

7740448798710

result:

ok single line: '7740448798710'

Test #31:

score: 0
Accepted
time: 19ms
memory: 28076kb

input:

49983 0
500000001 500000002 500000003 500000004 500000005 499999994 499999993 499999992 500000009 500000010 499999989 500000012 499999987 499999986 499999985 500000016 500000017 500000018 500000019 500000020 500000021 499999978 500000023 500000024 500000025 499999974 499999973 500000028 500000029 50...

output:

1000099953

result:

ok single line: '1000099953'

Test #32:

score: 0
Accepted
time: 15ms
memory: 28036kb

input:

49993 0
499999999 500000002 499999997 500000004 500000005 500000006 500000007 499999992 500000009 500000010 500000011 500000012 500000013 499999986 500000015 499999984 500000017 500000018 500000019 500000020 499999979 499999978 500000023 499999976 500000025 499999974 500000027 500000028 500000029 50...

output:

1000099975

result:

ok single line: '1000099975'

Test #33:

score: -15
Time Limit Exceeded

input:

49973 0
500049973 499950028 500049971 499950030 500049969 499950032 499950033 500049966 499950035 499950036 499950037 500049962 499950039 499950040 499950041 499950042 499950043 499950044 500049955 500049954 500049953 499950048 500049951 499950050 499950051 500049948 500049947 499950054 499950055 50...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%