Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cstdio>
- #include <cstdlib>
- #include <ctime>
- #include <vector>
- #include <cmath>
- #include <stack>
- #include <queue>
- #include <set>
- using namespace std;
- #define mp make_pair
- #define pb push_back
- #define x first
- #define y second
- typedef long long ll;
- typedef long double ld;
- typedef short int si;
- typedef pair <int, int> pii;
- const int MOD = 1e9 + 7;
- const int INF = 2e9 + 5;
- const int N = 2e5 + 5;
- int n, k;
- struct fenv
- {
- int t[N];
- void add(int x, int d)
- {
- for (; x <= n; x = (x | (x + 1)))
- t[x] += d;
- }
- int res(int x)
- {
- int sum = 0;
- for (; x >= 0; x = (x & (x + 1)) - 1)
- sum += t[x];
- return sum;
- }
- int sum(int l)
- {
- return res(n) - res(l);
- }
- };
- int a[N], x, ans[N];
- fenv b, c;
- int main()
- {
- freopen("battle.in", "r", stdin);
- freopen("battle.out", "w", stdout);
- cin >> n >> k;
- for (int i = 0; i < n; i++)
- {
- scanf("%d", &x);
- x--;
- a[x] = b.sum(x);
- b.add(x, 1);
- }
- for (int i = 0; i < n; i++)
- a[i] = max(0, a[i] - k);
- for (int i = 0; i < n; i++)
- {
- int l = 0, r = n, m;
- while (l + 1 < r)
- {
- m = (l + r) / 2;
- if (m - (m ? c.res(m - 1) : 0) > a[i]) r = m;
- else l = m;
- }
- c.add(l, 1);
- ans[l] = i;
- }
- for (int i = 0; i < n; i++)
- cout << ans[i] + 1 << " ";
- return 0;
- }
- /*
- 5859589000
- 17053987120
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement