Submission #13927

#TimeUsernameProblemLanguageResultExecution timeMemory
13927model_code버블 정렬 (OJUZ10_bubblesort)C++98
100 / 100
69 ms3232 KiB
#include<stdio.h> #include<algorithm> using namespace std; struct nums { int num, nwid; bool operator< (const nums& c) const { if(num != c.num)return num<c.num; return nwid<c.nwid; } }ba[100100]; int n, k; int j2, itr[250100], dap[100100]; void upd(int num, int wd){ int cnt=1; if(wd<0)wd=0; wd+=j2; while(1){ if(itr[wd]==cnt){ if(wd%2==1)wd++; else wd/=2, cnt*=2; } else{ if(cnt==1)break; if(itr[wd*2]==cnt/2)wd=wd*2+1; else wd*=2; cnt/=2; } } dap[wd-j2]=num; for(;wd; wd/=2)itr[wd]++; } int main(){ int i; scanf("%d%d", &n, &k); for(j2=1; j2<n; j2<<=1); for(i=0; i<n; i++){ scanf("%d", &ba[i].num); ba[i].nwid=i; } sort(ba, ba+n); for(i=0; i<n; i++)upd(ba[i].num, ba[i].nwid-k); for(i=0; i<n; i++)printf("%d ", dap[i]); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...