Submission #38698
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | #include<bits/stdc++.h> #define ll int using namespace std; vector<ll> v,vv; pair< char ,ll> a[1000000]; ll up(ll b,ll n); ll fa(ll l,ll r,ll b,ll c,ll d); int main(){ ll n,k,i,j,mi,r,l,mid,cnt=0,f=0; string s; cin>>s; n=s.size(); i=1; while (n>i){ i*=2; } n=i; for (i=n-1;i<n*2-1;i++){ a[i].first= '{' ; a[i].second=i+n+n; } a[900000].first= '{' ; a[900000].second=n*3; for (i=0;i<s.size();i++){ a[i+n-1].first=s[i]; a[i+n-1].second=i; v.push_back(i); up(i,n); } cin>>k; for (i=1;i<s.size();i++){ if (s[i-1]>s[i]){ f=1; } } if (f==1){ while (k>0&&!v.empty()){ if (v.size()-1>k){ mi=k; } else { mi=v.size()-1; } i=fa(0,v[mi],0,0,n-1); l=0; r=v.size(); mid=(r+l)/2; while (v[mid]!=a[i].second&&r>=l){ mid=(r+l)/2; if (v[mid]>a[i].second){ r=mid-1; } if (v[mid]<a[i].second){ l=mid+1; } } k-=mid; vv.push_back(v[mid]); v.erase(v.begin()+mid); a[n-1+a[i].second].first= '{' ; up(a[i].second,n); } } cnt=0; while (cnt<vv.size()){ cout<<s[vv[cnt]]; cnt++; } cnt=0; while (cnt<v.size()){ cout<<s[v[cnt]]; cnt++; } cout<<endl; return (0); } ll fa(ll l,ll r,ll b,ll c,ll d){ ll x,y; if (d<l||r<c){ return (900000); } else { if (l<=c&&d<=r){ return (b); } else { x=fa(l,r,b*2+1,c,(c+d)/2); y=fa(l,r,b*2+2,(c+d)/2+1,d); if (a[x].first>a[y].first){ return (y); } else { return (x); } } } return (0); } ll up(ll b,ll n){ b=b+n-1; while (b>0){ b=(b-1)/2; if (a[b*2+1].first>a[b*2+2].first){ if (a[b].first==a[b*2+2].first&&a[b].second==a[b*2+2].second){ b=0; } else { a[b].first=a[b*2+2].first; a[b].second=a[b*2+2].second; } } else { if (a[b].first==a[b*2+1].first&&a[b].second==a[b*2+1].second){ b=0; } else { a[b].first=a[b*2+1].first; a[b].second=a[b*2+1].second; } } } return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 0963 - 人気のユーザ名 |
ユーザー名 | 珈琲の素材は虚数渦動 |
投稿日時 | 2018-07-12 16:51:21 |
言語 | C++11 |
状態 | Accepted |
得点 | 14 |
ソースコード長 | 2137 Byte |
最大実行時間 | 470 ms |
最大メモリ使用量 | 8516 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 14 / 14 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in1.txt | AC | 23 ms | 604 KB |
1
|
in2.txt | AC | 20 ms | 716 KB |
1
|
in3.txt | AC | 20 ms | 1676 KB |
1
|
in4.txt | AC | 20 ms | 1944 KB |
1
|
in5.txt | AC | 22 ms | 2028 KB |
1
|
in6.txt | AC | 23 ms | 1992 KB |
1
|
in7.txt | AC | 21 ms | 2084 KB |
1
|
in8.txt | AC | 16 ms | 1916 KB |
1
|
in9.txt | AC | 21 ms | 2136 KB |
1
|
in10.txt | AC | 20 ms | 436 KB |
1
|
in11.txt | AC | 27 ms | 404 KB |
1
|
in12.txt | AC | 20 ms | 496 KB |
1
|
in13.txt | AC | 24 ms | 456 KB |
1
|
in14.txt | AC | 31 ms | 424 KB |
1
|
in15.txt | AC | 21 ms | 388 KB |
1
|
in16.txt | AC | 15 ms | 476 KB |
1
|
in17.txt | AC | 27 ms | 5164 KB |
1
|
in18.txt | AC | 26 ms | 5168 KB |
1
|
in19.txt | AC | 23 ms | 5308 KB |
1
|
in20.txt | AC | 470 ms | 5540 KB |
1
|
in21.txt | AC | 30 ms | 7892 KB |
1
|
in22.txt | AC | 142 ms | 8100 KB |
1
|
in23.txt | AC | 105 ms | 8308 KB |
1
|
in24.txt | AC | 55 ms | 8516 KB |
1
|
in25.txt | AC | 22 ms | 1808 KB |
1
|
in26.txt | AC | 17 ms | 1768 KB |
1
|
in27.txt | AC | 20 ms | 1848 KB |
1
|
in28.txt | AC | 21 ms | 1780 KB |
1
|
in29.txt | AC | 19 ms | 1856 KB |
1
|
in30.txt | AC | 24 ms | 1764 KB |
1
|
in31.txt | AC | 304 ms | 8112 KB |
1
|
in32.txt | AC | 242 ms | 6600 KB |
1
|