QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#19644 | #2471. Minimizing Haybales | wlzhouzhuan | 100 ✓ | 1042ms | 376104kb | C++17 | 2.3kb | 2022-02-07 13:13:04 | 2022-05-06 06:33:50 |
Judging History
answer
// Author: wlzhouzhuan
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define mset(s,t) memset(s,t,sizeof(s))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define SZ(x) ((int)x.size())
#define pb push_back
#define eb emplace_back
#define fir first
#define sec second
template<class T1,class T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<class T1,class T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
inline int read(){
int x=0,f=0;char ch=getchar();
while(!isdigit(ch))f|=ch=='-',ch=getchar();
while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
return f?-x:x;
}
template<typename T>void print(T x){
if(x<0)putchar('-'),x=-x;
if(x>=10)print(x/10);
putchar(x%10+'0');
}
template<typename T>void print(T x,char ch){
print(x),putchar(ch);
}
const int N=100005;
const int M=10000005;
const int inf=1e9;
vector<int>adj[M];int deg[M];
void add(int u,int v){
// printf("addedge %d->%d\n",u,v);
if(!u||!v)return;
adj[u].pb(v),deg[v]++;
}
int ls[M],rs[M],tot;
int rt[N],a[M],n,K;
void ins(int &u,int v,int l,int r,int pos,int who){
u=++tot,ls[u]=ls[v],rs[u]=rs[v],add(u,v);
if(l==r){add(u,who);return;}
int mid=l+r>>1;
if(pos<=mid)ins(ls[u],ls[v],l,mid,pos,who),add(u,ls[u]);
else ins(rs[u],rs[v],mid+1,r,pos,who),add(u,rs[u]);
}
void query(int u,int l,int r,int ql,int qr,int who){
if(!u)return;
if(ql<=l&&r<=qr){add(who,u);return;}
int mid=l+r>>1;
if(ql<=mid)query(ls[u],l,mid,ql,qr,who);
if(qr>mid)query(rs[u],mid+1,r,ql,qr,who);
}
void topo(){
priority_queue<pii,vector<pii>,greater<pii>>pq;
rep(i,1,tot)if(!deg[i])pq.push({a[i],i});
while(!pq.empty()){
auto _=pq.top();pq.pop();
int u=_.sec;
if(u<=n)print(a[u],'\n');
for(auto v:adj[u])if(--deg[v]==0)pq.push({a[v],v});
}
}
int main(){
n=read(),K=read(),tot=n;
rep(i,1,n)a[i]=read();
per(i,n,1){
ins(rt[i],rt[i+1],0,inf,a[i],i);
query(rt[i+1],0,inf,0,max(0,a[i]-K-1),i);
query(rt[i+1],0,inf,min(inf,a[i]+K+1),inf,i);
}
topo();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 61ms
memory: 237884kb
input:
5 3 7 7 3 6 2
output:
6 7 7 2 3
result:
ok 5 lines
Test #2:
score: 5
Accepted
time: 62ms
memory: 238224kb
input:
100 500000276 870008509 927469041 935406318 944203501 797721875 788862150 829670356 907559578 718374630 509907701 522634718 660868664 786521954 514117566 807678427 549891686 591859900 641495303 610385740 767798197 477652779 748746451 738282716 590882275 255562601 627012345 570543971 246778294 546323...
output:
446452076 450190489 457330701 460651686 460776808 461454886 474154009 475530095 477466533 477652779 478979648 491341754 509907701 511989080 514117566 514156865 522634718 536476244 546016428 546323236 549891686 551547512 555501463 556127591 559365249 570543971 590882275 591859900 610385740 626472443 ...
result:
ok 100 lines
Test #3:
score: 5
Accepted
time: 73ms
memory: 244776kb
input:
5000 500000092 876873178 532909908 691231781 552601748 634859059 954722077 566913744 669033129 599030880 854902273 508962949 541446119 849630596 521171484 854895876 694002393 893301389 816678419 774687296 913625357 872369003 637310311 838609600 869273073 694873732 670936633 602033085 532798697 82220...
output:
474057275 474118290 474165237 474211691 474286361 474328081 474806475 474939204 475030713 475089865 475167222 475253362 475395832 475445731 475500181 475780488 475963620 476531278 476579992 476704749 476773812 476786185 477023255 477046377 477068547 477123436 477279964 477308036 477361210 477366468 ...
result:
ok 5000 lines
Test #4:
score: 5
Accepted
time: 62ms
memory: 244924kb
input:
5000 500000051 749316321 730453003 913575059 862976693 686029006 822819868 660394491 970141114 743840810 646769530 764878371 554715136 639686703 578137696 723949039 969360006 634776293 889588783 497384805 752832200 937051443 660927236 715318931 794792652 502702405 764452841 678276888 843647569 56528...
output:
474267507 474271404 474278271 474300880 474334065 474386850 474416640 474436878 474465440 474489938 474555946 474575746 474727262 474825095 474831863 475084999 475128503 475351079 475611854 475669867 475766168 475908282 475917084 475943330 475965005 476063803 476255945 476334073 476441476 476539638 ...
result:
ok 5000 lines
Test #5:
score: 5
Accepted
time: 76ms
memory: 244988kb
input:
5000 499999903 702811695 667164672 977793322 975303193 824282596 853496670 576220647 628576954 836044525 737259702 602176636 559657696 767313699 565325752 556326779 906531829 849279179 657326131 725965296 850271786 619939890 750919964 677011765 519852573 505008517 583852726 590379643 993871739 78868...
output:
493890731 494002838 494022450 494028649 494131900 494369938 494422316 494447334 494485029 494531231 494689152 494752080 494856395 494905365 494927294 495106280 495228276 495289896 495384277 495388810 495660130 495918240 496006866 496055693 496236012 496328240 496370388 496399098 496409924 496425206 ...
result:
ok 5000 lines
Test #6:
score: 5
Accepted
time: 99ms
memory: 244816kb
input:
5000 499999659 864999430 633751501 669999080 642742789 885259094 670121204 556089694 777210903 600413470 672705529 943764014 863356225 831596424 625421162 580776758 662988069 671341336 601389842 729095269 956874925 861105302 775856455 709104580 619579778 891488276 801782435 776726417 640060238 67894...
output:
481832753 481851893 481956990 481968365 482020931 482045243 482118840 482138212 482138413 482250207 482751132 482924209 482968904 483000625 483058415 483154289 483352788 483397770 483601861 483630428 483684825 484016979 484129639 484237319 484262016 484473250 484519653 484586352 484602372 484667937 ...
result:
ok 5000 lines
Test #7:
score: 5
Accepted
time: 971ms
memory: 376036kb
input:
100000 499999689 522308516 569502884 647941518 853228330 654821520 838881796 774403511 736611222 842053880 606723975 985926270 876060090 622595727 721250785 565765709 901002668 885374363 550172010 575300705 622879464 613382203 748567965 834846154 522172750 905759483 865754687 766509821 877494171 688...
output:
495518361 495528835 495534851 495535656 495536789 495538870 495542608 495556169 495564109 495570347 495576609 495578897 495587847 495598047 495598716 495615725 495620306 495620866 495625633 495629369 495643787 495644874 495652894 495655330 495657359 495660728 495663333 495663748 495663958 495665064 ...
result:
ok 100000 lines
Test #8:
score: 5
Accepted
time: 922ms
memory: 376104kb
input:
100000 500000173 990775780 688545127 646804699 788353753 676568883 868340410 671589000 953696111 686961724 632973188 690696234 715740373 606233240 986146202 878874984 876162656 805622883 872090728 943178960 549978890 534761731 920736091 922133710 550450440 521883016 957548511 618568746 900617604 684...
output:
494855999 494862352 494865539 494870674 494879081 494880444 494881056 494884287 494892230 494898314 494909665 494915449 494917679 494921145 494933397 494934372 494935127 494936763 494943712 494973089 494976847 494979446 494982890 494985342 494996593 495003505 495005453 495011396 495016968 495020861 ...
result:
ok 100000 lines
Test #9:
score: 5
Accepted
time: 925ms
memory: 375896kb
input:
100000 499999716 961588881 622373216 829499649 652387956 977516383 700720874 645867135 639942519 754115351 921339422 911466113 625208629 689630195 515383601 988113721 933210955 838954714 861832012 706977319 760273274 888479052 736553881 755517402 878593223 504701750 609043772 808564727 832346308 560...
output:
495252198 495252915 495255231 495255661 495266335 495266909 495272909 495275186 495275478 495285391 495296305 495300517 495301338 495306768 495306984 495307894 495309676 495311939 495315256 495315702 495318355 495323237 495324973 495336922 495342751 495354498 495361213 495372325 495374300 495383042 ...
result:
ok 100000 lines
Test #10:
score: 5
Accepted
time: 945ms
memory: 375912kb
input:
100000 499999965 586906664 785816875 559096748 568160809 770057713 850543684 756484838 907031258 527090020 522959969 641247309 949869480 758386508 932086404 515720675 576910674 593776180 949716385 627436089 821828286 824335653 731598966 718315347 948821073 835614578 811476996 933352148 966236635 539...
output:
497204989 497207004 497222654 497225955 497226160 497227336 497236927 497239596 497240454 497244706 497265799 497271855 497277511 497283163 497290125 497290770 497308775 497308792 497319919 497324698 497328894 497329318 497339286 497343417 497344162 497346598 497346855 497347431 497349462 497356828 ...
result:
ok 100000 lines
Test #11:
score: 5
Accepted
time: 979ms
memory: 376096kb
input:
100000 500000064 800447926 719877542 990685270 969136566 682887012 838675215 864935401 714661764 530927165 679393693 956117153 702480839 626387388 989915213 928788904 839482826 824747011 589575242 623294421 993905764 884185517 621887958 905767207 662279311 915752607 706993074 719873247 517440314 866...
output:
495965532 495972155 495972442 495973880 495985800 495986695 495987127 495987959 495989397 495989605 496007657 496007712 496021186 496028045 496035235 496035674 496037300 496040071 496044792 496044858 496047343 496049790 496052659 496055642 496057080 496067667 496074156 496075714 496078341 496081237 ...
result:
ok 100000 lines
Test #12:
score: 5
Accepted
time: 917ms
memory: 376012kb
input:
100000 500000060 589831436 926568471 502623185 947521508 706193200 557638536 997440264 787829453 918788862 565820605 533958147 520184188 591412798 858622437 566507151 505585645 951723905 663551950 693693740 835296306 871871823 597202943 779246896 557471338 608936726 730216642 745404224 962757882 534...
output:
497445724 497449640 497449966 497474210 497477030 497478152 497480594 497494664 497500552 497503846 497504427 497504972 497505405 497509579 497514237 497514426 497516150 497518238 497524834 497528099 497530628 497531726 497534723 497535096 497538608 497544737 497548537 497549556 497549797 497558685 ...
result:
ok 100000 lines
Test #13:
score: 5
Accepted
time: 989ms
memory: 375836kb
input:
100000 499999703 998339676 857775038 938914859 925714046 948420452 853099930 702807605 955309563 507771407 859625378 599746541 526518608 920399831 749583607 933937091 505693947 944593139 528674523 690902369 714593203 991924301 646559431 532682045 661736933 567787144 857175318 885277238 521134842 982...
output:
498340858 498341849 498348507 498349348 498351230 498353608 498361619 498363602 498364895 498365498 498366816 498376759 498377914 498379115 498391958 498394684 498396612 498404555 498410255 498410541 498419520 498422454 498425663 498432036 498440190 498441773 498442459 498446812 498448587 498449231 ...
result:
ok 100000 lines
Test #14:
score: 5
Accepted
time: 974ms
memory: 375828kb
input:
100000 499999711 695301689 560039379 672448134 824685585 739913206 539784434 829510060 577250390 747928670 789519051 700730081 983775810 680977333 944727662 719765522 500161311 542770816 777742933 893127614 559516227 835046023 984518913 596526140 984853995 970871415 705149090 603278546 582372794 636...
output:
494433622 494436837 494444321 494448125 494448875 494455819 494469205 494469560 494483948 494484981 494490537 494493676 494505968 494506484 494508981 494512599 494516145 494531572 494533481 494535402 494535435 494536263 494539276 494541205 494550706 494551507 494554288 494561538 494566521 494567411 ...
result:
ok 100000 lines
Test #15:
score: 5
Accepted
time: 952ms
memory: 376088kb
input:
100000 500000138 823666089 992527097 695616352 557997486 997702307 835297060 932083132 545631833 560499050 593683633 907385849 772551018 586965709 537600892 927874503 501188040 864814223 882492756 981357762 675430235 913880748 585118641 638762120 740292839 793367806 941851372 581443270 626820208 647...
output:
498549314 498551219 498555412 498560119 498568225 498577851 498577895 498580724 498583616 498584281 498584628 498589984 498595248 498600184 498604794 498606100 498616179 498618743 498625793 498625804 498626725 498627984 498629977 498638859 498639200 498649991 498651058 498658960 498659212 498662692 ...
result:
ok 100000 lines
Test #16:
score: 5
Accepted
time: 997ms
memory: 376032kb
input:
100000 499999705 865090747 621645284 675347345 579476019 926856164 807987057 743784877 648624896 903529805 506002020 730071335 825738820 851461903 952937940 976585398 862928172 557065763 852749968 724179644 776502490 808082334 879988163 576224601 678164425 510668021 517980414 736920241 608815772 707...
output:
495159248 495161554 495165250 495167126 495168379 495170100 495173263 495174633 495180737 495181397 495185748 495186467 495187656 495195288 495204061 495204591 495222926 495227699 495233226 495242945 495244659 495248099 495252178 495252298 495254381 495257818 495266743 495282066 495298893 495301052 ...
result:
ok 100000 lines
Test #17:
score: 5
Accepted
time: 1012ms
memory: 375992kb
input:
100000 499999940 561770745 700083067 772417184 630455486 566589619 527373256 680269837 688334775 761016347 579979332 685620463 991340939 584822162 805408134 987166410 662089268 507799971 961997465 993145421 832196907 865751924 707107786 895138059 606455281 545671384 509993873 626782787 762183648 927...
output:
499234271 499237022 499244985 499247530 499252631 499268917 499270252 499281417 499283012 499283537 499284938 499286395 499293551 499295811 499297495 499305193 499322043 499323860 499335617 499342717 499352485 499357547 499364277 499378365 499382358 499388600 499392685 499398699 499401459 499405664 ...
result:
ok 100000 lines
Test #18:
score: 5
Accepted
time: 1042ms
memory: 376080kb
input:
100000 499999942 776408462 987292704 934126535 949242623 825796635 551007297 855992436 600237028 622519904 803204712 913549773 618035582 974580612 887892434 842260331 627314120 825838659 674502706 620244094 993146835 852442975 998472146 882123654 822630659 984406455 654646083 568954801 826585448 838...
output:
498473390 498478346 498478958 498508477 498516058 498517843 498526165 498543091 498558141 498558756 498561399 498567598 498570544 498573480 498573979 498578029 498580500 498582907 498583240 498583882 498585119 498587795 498592729 498607801 498612028 498613418 498614125 498618763 498622276 498628516 ...
result:
ok 100000 lines
Test #19:
score: 5
Accepted
time: 979ms
memory: 375904kb
input:
100000 500000301 631259614 927632295 867812128 865876610 584436269 797968706 898096753 768508948 691818764 843399208 842839446 754773737 780882621 984461159 731777715 950749057 913447489 738723219 645875959 968509216 690880878 540952366 722322777 651452633 921593682 884544922 657336539 553175341 938...
output:
497058972 497060844 497065716 497070930 497071940 497088510 497096752 497103405 497111453 497127922 497128999 497136033 497146064 497154363 497155543 497174603 497182695 497189763 497208353 497209525 497217388 497226696 497229006 497230843 497232980 497235744 497255752 497256341 497258977 497261154 ...
result:
ok 100000 lines
Test #20:
score: 5
Accepted
time: 981ms
memory: 375960kb
input:
100000 499999684 846689960 872461622 903406427 821748465 508090323 670625273 962758034 722267965 825104333 996701168 997229041 977256026 950729017 532350029 525131720 529706299 849983259 848516122 943100355 746778579 857884167 536055778 960947123 759580048 962328565 722242046 629455900 779438545 619...
output:
498807888 498813092 498834211 498841800 498870489 498873312 498882392 498886159 498895689 498902570 498903018 498912528 498920924 498923948 498926082 498926912 498927044 498931450 498932517 498937778 498939093 498944616 498946120 498948066 498950450 498952859 498960723 498969976 498970178 498991564 ...
result:
ok 100000 lines