提交时间:2024-11-19 13:31:43

运行 ID: 34842

// 鏈嶄簡銆傜湅浜嗗崐澶╂墠鍙戠幇璇堥獥銆?:33鐮佸畬銆? #include <bits/stdc++.h> #define int long long using namespace std; char s[100005]; int k, n; struct node { int val, i; } a[100005]; inline bool cmp(node x, node y) { return x.val > y.val; } set<int> st; vector<int> az; int c[100005]; bool vis[100005]; inline int lb(int x) { return x & (-x); } inline void upd(int x, int y) { for (; x <= n; x += lb(x)) c[x] += y; } inline int qry(int x) { int ret = 0; for (; x >= 1; x -= lb(x)) ret += c[x]; return ret; } list<signed> l; list<signed>::iterator it[100005]; long double cc[100005]; signed main() { freopen("swap.in", "r", stdin); freopen("swap.out", "w", stdout); scanf("%s\n%lld", s + 1, &k); cc[0] = k; n = strlen(s + 1); for (int i = 1; i <= n; i++) { cc[i] = cc[i - 1] * 0.1; a[i].i = i; s[i] -= '0'; a[i].val = s[i]; l.push_back(s[i]); it[i] = l.end(); it[i]--; } stable_sort(a + 1, a + n + 1, cmp); int cf = 1; // int cur = 0; for (int i = 1; i <= n; i++) { // printf("%lld %lld\n", a[i].i, a[i].val); if (a[i].i == cf) { cf++; upd(a[i].i, 1); az.emplace_back(a[i].val); st.insert(a[i].i); l.erase(it[a[i].i]); vis[a[i].i] = 1; continue; } int ps = a[i].i - qry(a[i].i); if (ps >= 20) { if (s[cf] == a[i].val) { continue; } upd(a[i].i, 1); az.emplace_back(a[i].val); st.insert(a[i].i); l.erase(it[a[i].i]); vis[a[i].i] = 1; // cur++; continue; } // if (s[cf] == a[i].val) // continue; auto p = l.begin(); int c1 = a[i].val, c2 = 0; for (; p != it[a[i].i]; p++) { c1 = c1 * 10 + *p; c2 = c2 * 10 + *p; } c2 = c2 * 10 + a[i].val; // printf("%lld %lld %lld %lld\n", c1, c2, k, (ps - 1)); if (c1 - c2 >= cc[n - a[i].i - qry(n) + qry(a[i].i)] * (ps - 1)) { // printf("fsdanlihngasdf"); upd(a[i].i, 1); az.emplace_back(a[i].val); st.insert(a[i].i); l.erase(it[a[i].i]); vis[a[i].i] = 1; // cur++; } } for (signed i : az) { // if (cnt == az.size()) // printf("g"); // else printf("%d", i); } for (signed i : l) { printf("%d", i); } return 0; }