Submission #15743

#TimeUsernameProblemLanguageResultExecution timeMemory
15743cki86201버블 정렬 (OJUZ10_bubblesort)C++98
100 / 100
111 ms3556 KiB
#include<stdio.h> #include<algorithm> #include<set> #include<vector> using namespace std; typedef long long ll; typedef pair<int,int> Pi; #define X first #define Y second int p[100010], n, k, q[100010], per[100010], s[100010]; struct BIT{ int r[100010]; void update(int x){for(int i=x+1;i<=n;i+=(i&-i))r[i]++;} int read(int x){ int ret = 0; for(int i=x+1;i;i-=(i&-i))ret += r[i]; return ret; } void clear(){for(int i=1;i<=n;i++)r[i] = 0;} }bit; bool comp(const int &a, const int &b){return p[a] < p[b];} int main(){ scanf("%d%d",&n,&k); for(int i=0;i<n;i++)scanf("%d",p+i); for(int i=0;i<n;i++)per[i] = i; stable_sort(per, per+n, comp); for(int i=0;i<n;i++){ s[i] = max(per[i] - bit.read(per[i]) - k, 0); bit.update(per[i]); } bit.clear(); for(int i=0;i<n;i++){ int low=0, high=n-1, cor=0; while(low<=high){ int mid = (low+high) / 2; if(s[i] <= mid - bit.read(mid))cor = mid, high = mid - 1; else low = mid + 1; } q[cor] = p[per[i]]; bit.update(cor); } for(int i=0;i<n;i++)printf("%d ",q[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...