QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#139648#5405. 爬楼梯1kri#30 55ms3980kbC++14869b2023-08-14 08:54:492024-07-04 01:41:41

Judging History

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

  • [2024-07-04 01:41:41]
  • 评测
  • 测评结果:30
  • 用时:55ms
  • 内存:3980kb
  • [2023-08-14 08:54:49]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
int n,m;
int a[200005];
int l,r;
int len,c[200005];
struct node{
	int l,r,c;
	ll s;
};
ll work(){
	ll ans=0;
	sort(c+1,c+1+len);
	if (len&1){
		int mid=(len+1)/2;
		for (int i=1;i<=len;i++)ans+=2ll*c[i];
		for (int i=1;i<mid;i++)ans-=4ll*c[i];
		ans-=min(0ll+c[mid]+c[mid+1],3ll*c[mid]-c[mid-1]);
	}
	else{
		int mid=len/2;
		for (int i=1;i<=len;i++)ans+=2ll*c[i];
		for (int i=1;i<=mid;i++)ans-=4ll*c[i];
		ans-=c[mid+1];
		ans+=c[mid];
	}
	return ans;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	while(m--){
		scanf("%d%d",&l,&r);
		len=0;
		for (int i=l;i<=r;i++)c[++len]=a[i];
		sort(c+1,c+1+len);
		ll ans=0;
		ans+=work();
		printf("%lld\n",ans);
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 3956kb

input:

10 10
323351358 540774025 513831404 171513818 162079008 234580967 887182642 765979034 329924749 677555871
2 4
1 6
8 10
2 5
1 9
4 6
9 10
2 10
1 8
8 10

output:

711577793
1530795597
783685407
1099707620
3625910517
135569108
347631122
3919843439
3442003862
783685407

result:

ok 10 numbers

Test #2:

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

input:

10 10
356685563 915148434 563845435 480227923 510014130 571548808 489307692 666691543 573877683 800166552
5 8
1 4
1 10
3 10
1 7
3 8
5 8
5 6
5 6
2 4

output:

416302380
1200543254
2247001181
1130075439
1427936560
591240777
416302380
61534678
61534678
786223510

result:

ok 10 numbers

Test #3:

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

input:

10 10
259041296 18437783 835927251 200068667 931291913 220668768 841571584 64630364 869262858 448307535
5 10
4 9
4 9
3 10
8 10
4 6
2 5
2 4
1 4
3 8

output:

3423775327
3692614296
3692614296
4701136828
1225587817
1441846391
2461566844
1453348052
1693951565
3631587415

result:

ok 10 numbers

Test #4:

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

input:

10 10
694546061 683750732 282826928 44704999 202358913 413195054 57606354 882383775 603016817 756343723
3 10
1 9
2 10
6 8
3 5
5 7
1 8
1 7
4 6
1 4

output:

4004516224
4422032256
4545627580
1293966142
395775843
566424841
4042388730
2893175147
579326196
1700605928

result:

ok 10 numbers

Test #5:

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

input:

10 10
75522620 489110151 476088987 919220128 114109105 664499311 296664800 117714384 936389932 742669420
5 10
1 10
4 10
1 2
3 9
2 4
1 6
6 8
2 4
5 6

output:

3262306237
5330556928
4061412273
413587531
3803817977
873241118
2801196592
914619438
873241118
550390206

result:

ok 10 numbers

Test #6:

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

input:

10 10
708842660 535631736 313983181 60960887 709239973 805842351 640508065 995203777 786390356 570768327
5 7
7 9
7 10
7 9
2 8
6 8
4 10
8 10
5 6
3 5

output:

261936664
563509133
994753191
563509133
3130688686
544057138
2561666502
640057479
96602378
1043535878

result:

ok 10 numbers

Test #7:

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

input:

10 10
949140873 817668912 216488537 181549618 394932991 526353574 808587752 448239013 817070969 296679334
6 10
2 8
2 7
1 8
6 10
3 6
5 8
2 3
4 10
2 7

output:

1683366187
2665972162
2587857601
3642967343
1683366187
868052366
905424083
601180375
2504394682
2587857601

result:

ok 10 numbers

Test #8:

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

input:

10 10
216976438 311196676 362414991 166779537 394400237 257402421 7949303 795846086 161382188 190830847
4 8
6 9
6 9
4 7
3 9
1 7
4 9
2 7
7 10
4 8

output:

1940412082
1671813799
1671813799
863524752
2342477688
1312187269
2132452548
1217967031
1605242225
1940412082

result:

ok 10 numbers

Test #9:

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

input:

10 10
168117094 215701804 648251116 480535594 268077263 814190009 150894926 29759319 963450984 384460880
6 8
1 7
2 8
2 9
1 3
3 4
3 8
6 8
4 10
2 4

output:

1447725773
2764150331
3040865881
4271530451
912683334
167715522
2776032091
1447725773
3522815444
697383102

result:

ok 10 numbers

Test #10:

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

input:

10 10
16571107 681078796 450724252 846525392 447473866 502898147 991995131 660439261 933193062 456232325
4 7
4 9
1 6
1 8
3 5
2 3
7 9
2 7
3 10
5 7

output:

1432669775
2135718491
2179292325
3367201302
794852666
230354544
604309671
2058825459
2992107398
1033618249

result:

ok 10 numbers

Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 0
Time Limit Exceeded

input:

200000 200000
1 2 1 2 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 1 1 2 2 1 1 1 1 1 1 2 2 2 1 1 2 2 1 2 1 2 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 2 1 2 2 1 1 2 1 1 1 2 1 1 2 1 2 1 1 1 2 1 2 2 2 2 1 2 2 1 1 2 2 1 2 2 1 1 1 1 2 2 2 1 1 1 1 1 2 2 1 1 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 1 2 1 2 2 2 1 1 1 ...

output:

17766
92870
56732
16462
79590
3872
79674
3370
151158
52672
41424
27644
52872
33690
47896
76136
59296
75972
113274
89092
114330
48490
24112
6810
164898
10914
9738
3316
33638
1510
16344
10722
89260
87924
12710
11498
464
61810
9336
100798
59812
170450
7374
78296
10230
173826
56696
106278
7504
141524
52...

result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 25
Accepted

Dependency #1:

100%
Accepted

Test #31:

score: 25
Accepted
time: 47ms
memory: 3928kb

input:

2000 2000
934094958 536783701 145230662 389097466 662916743 15680595 497269445 277327696 295204335 399565879 103085285 660476806 406097164 491009942 123591789 940451006 657478375 690285007 370217804 34759017 896304691 785120106 102507838 814135240 179075942 374826926 706283825 750182730 494056277 17...

output:

273757423642
66476977112
237905924503
268145773779
1009274567874
133235037708
490463511544
488261294368
281356752080
752867613163
140878891959
116280565475
431247126230
47187175834
623046882965
168840754351
84041149197
380784864121
163937321134
258535804412
446360806108
98427472953
348024159178
9069...

result:

ok 2000 numbers

Test #32:

score: 0
Accepted
time: 54ms
memory: 3924kb

input:

2000 2000
430676823 601313211 831915691 571317219 725924558 359178143 624054422 334329457 97735569 856155674 622583253 647480072 233495215 952504395 933848132 946405571 119999572 531138207 563350953 468019888 525396948 259152810 547609710 173524832 37300825 977998768 298207574 937208131 54221721 646...

output:

572256829943
664805649055
156946619190
609964613731
133184514146
27573811698
176175454437
480273237819
15693149570
496044812586
339601590747
60339154451
402831452507
396565742189
145255610947
684304273826
529869367988
569576214542
364096388216
239357736074
76777255979
141189744624
104700932792
29812...

result:

ok 2000 numbers

Test #33:

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

input:

2000 2000
174014840 454415074 704208482 737283911 176268494 955596481 780620368 922940830 113662017 357753017 180602769 884541098 995110533 972424845 416643161 17062213 59822798 882594371 179243682 831650483 518716292 444497323 11781122 374065322 88742263 810718669 323090508 515110143 884032936 9006...

output:

22816186265
77800170465
109794318366
761973373672
667874385722
58937127966
673298255202
656249241920
373037668739
259563617900
892391641970
700898503534
589031039697
404791205133
463770946434
341922338103
325308823975
372238431670
86960098391
131814497048
422475685926
168082709910
428731393681
20723...

result:

ok 2000 numbers

Test #34:

score: 0
Accepted
time: 50ms
memory: 3968kb

input:

2000 2000
766609373 691046189 418705023 140123391 241375284 728021370 306085912 960170889 751838082 60655025 321302475 664067546 65554601 738423524 688635939 367516811 151877071 698520791 266626686 9006258 985650154 436540781 195639925 303307967 756113825 493299175 423713836 514385263 129004034 6837...

output:

106398326007
444075111660
610789371553
41911178095
24368907326
589488250310
80760460010
73516225638
343138692052
608480252486
476374324497
147551648827
442304902889
480904439360
130609437487
523685232322
580578038221
936135819125
72980481206
298704673171
477890373591
873940554658
503392518601
328989...

result:

ok 2000 numbers

Test #35:

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

input:

2000 2000
891212336 408279194 565848724 135604011 129057392 879469233 618947043 569874482 735901400 183512627 587549837 572418048 367287101 196841752 624574109 464852804 675146995 338288381 433459574 555739681 984676194 115127560 953477351 254225509 418033665 994658443 331668454 241149416 892832595 ...

output:

547212804074
205771194015
333486581416
434141914457
341756217613
934556963115
453685752318
84922309760
940269005494
79033995712
495995780125
520016250954
8338652820
377605691349
48690451855
188223693504
749357214275
119206104803
228193087627
90751428033
717129505812
389354510408
593894845532
2342478...

result:

ok 2000 numbers

Test #36:

score: 0
Accepted
time: 54ms
memory: 3828kb

input:

2000 2000
807173723 997155885 419270522 935663725 907994153 434775316 156728805 573582873 964218336 897693638 148147286 734808404 245768500 440875090 961107912 397790456 923739660 156116150 98166935 461713740 437022167 104127972 639348136 853089968 538366721 694838933 485242447 167523330 939186585 4...

output:

766500559759
589679140895
150395877755
294329889604
628195695376
763776164556
396441632021
598437520894
721697370214
459397382254
232016405279
192206885310
12390529166
200873400822
156230263624
98275717561
693936500127
775027204810
84021105735
378266972679
541370083633
53345910650
11219676574
493004...

result:

ok 2000 numbers

Test #37:

score: 0
Accepted
time: 55ms
memory: 3980kb

input:

2000 2000
212521417 416574237 667588402 217263253 502694864 581047826 810159131 346030081 219031053 650358129 123544346 212980054 346630860 457301237 112931799 606517539 580390206 395607976 613186973 656120493 739930034 88705499 247560283 458317943 847419785 619362238 668913313 260719532 289431813 3...

output:

869009866222
796058030613
64004875968
365293671378
60668901837
769217825564
445399028935
150680900802
227157679155
64360178976
684185381404
259795137084
24454606503
215970172749
489063128868
52885676013
20554646079
882995288068
139119139694
24746656174
56976500940
691474317781
239170796505
756632924...

result:

ok 2000 numbers

Test #38:

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

input:

2000 2000
35890882 369605847 542056569 733407418 766672248 702007708 419920548 398879589 213854913 261894358 660194346 881124299 89901351 815239530 7033246 807633975 831205005 417554234 343541199 608284341 232793609 645022663 559597142 692586538 399928037 516620215 70284078 636526089 504735622 45073...

output:

234203498884
139403781378
59562729525
189131040262
28024577361
195340144124
71856217740
94600179097
281912519958
78097281573
158210947052
431655926756
436044750585
41699019036
572226747299
448929316840
171485631710
111606450461
140447490917
231694333428
160890552094
769720224560
611945982923
3018842...

result:

ok 2000 numbers

Test #39:

score: 0
Accepted
time: 50ms
memory: 3868kb

input:

2000 2000
661636400 560219770 459852949 229482128 598250483 161359788 157130457 76363928 392208323 34688283 65011889 327323787 854705792 599019820 956874290 528133115 568844284 979809792 380146932 989300539 574469058 976646053 175311403 474639310 445163210 558584734 679509015 752572539 732008023 721...

output:

248462475059
174715390624
587369878396
5864038656
111333836015
49060905026
415137874308
173786404310
385888151016
496816965736
32999135684
206478270702
368113626789
130208615270
514024725167
415817425650
80374038324
866370407850
292955076865
2451535467
548466582810
196620999192
725117557446
40359852...

result:

ok 2000 numbers

Test #40:

score: 0
Accepted
time: 55ms
memory: 3928kb

input:

2000 2000
907009150 50129623 814443705 62106767 631607632 803424557 509731948 710164263 254258872 514439222 781110806 661572333 114098981 670314213 202904104 891214898 268225132 356070882 800062334 221228736 149930659 955020793 266015184 131281825 246184627 487225990 107797484 935897116 451851837 78...

output:

307478406032
255977764737
397469624329
385813704241
672865530526
201844574227
53406749795
973978750658
580484394389
560269334368
229769045476
245695439336
918960950802
95002325100
76997236633
662075309473
26517974129
229329279683
214700364039
391295317323
435771899531
247697826258
565758183610
67039...

result:

ok 2000 numbers

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%