제출 #15739

#제출 시각아이디문제언어결과실행 시간메모리
15739cki86201버블 정렬 (OJUZ10_bubblesort)C++98
0 / 100
101 ms2772 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[110]; 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; sort(per, per+n, comp); vector <int> v; for(int i=0;i<n;i++){ if(i > 0 && p[per[i]] != p[per[i-1]]){ for(int j=0;j<(int)v.size();j++)bit.update(per[v[j]]); v.clear(); } s[i] = max(per[i] - bit.read(per[i]) - k, 0); v.push_back(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...