Submission #147581

#TimeUsernameProblemLanguageResultExecution timeMemory
147581KCSCTurnir (COCI17_turnir)C++14
100 / 100
819 ms25900 KiB
#include <bits/stdc++.h>
using namespace std;

const int DIM = (1 << 20) + 5;

int pwr[DIM], sol[DIM];
pair<int, int> arr[DIM];

int main(void) {
    int n;
    cin >> n;
    n = (1 << n);
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i].first;
        arr[i].second = i;
    }
    sort(arr + 1, arr + n + 1);
    for (int i = 2; i <= n; ++i)
        pwr[i] = pwr[i >> 1] + 1;
    for (int i = 1, j = 1; i <= n; ++i) {
        while (j + 1 <= n && arr[j + 1].first <= arr[i].first)
            ++j;
        sol[arr[i].second] = pwr[n] - pwr[j];
    }
    for (int i = 1; i <= n; ++i)
        cout << sol[i] << " ";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...