QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#610314#9249. Elimination Series Once Moreucup-team1001#Compile Error//C++205.4kb2024-10-04 15:34:402024-10-04 15:34:40

Judging History

你现在查看的是最新测评结果

  • [2024-10-04 15:34:40]
  • 评测
  • [2024-10-04 15:34:40]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;


class FIW {
    int n;
    vector<int> fiw;
public:
    FIW(int n) : n(n), fiw(n + 1) {

    }

    void add(int pos, int t) {
        while (pos <= n) {
            fiw[pos] += t;
            pos += pos & (-pos);
        }
    }

    int query(int pos) {
        int res = 0;
        while (pos) {
            res += fiw[pos];
            pos -= pos & (-pos);
        }
        return res;
    }

    int sum(int l, int r) {
        return query(r) - query(l - 1);
    }
};

void solve() {
    int n, m;
    cin >> n >> m;
    FIW fiw((1 << n) + 1);

    vector<int> arr((1 << n) + 1);
    vector<int> que((1 << n));
    iota(que.begin(), que.end(), 1);

    vector<int> ans((1 << n) + 1);
    for (int i = 1; i <= (1 << n); i++) {
        cin >> arr[i];
//        arr[i] = i;
    }
    sort(que.begin(), que.end(), [&](int a, int b) {
        return arr[a] < arr[b];
    });
    for (auto i: que) {
        fiw.add(i, 1);
        int l = i, r = i;
        int nums = arr[i];
        int t = 0;

//        cerr << "[" << i << "]\n";
        while (true) {

            int k = ((l - 1) >> t) & 1;
            if (k) {
                l -= 1 << t;
            } else {
                r += 1 << t;
            }
//            cerr << l << " " << r << endl;
            t++;
//            cerr << r - l + 1 << " " << fiw.sum(l, r) << " " << m << " " << (r - l + 1) - fiw.sum(l, r) << " " <<(  (r - l + 1) - fiw.sum(l, r) > m)<< endl;
            if (r - l + 1 > nums || (r - l + 1) - fiw.sum(l, r) > m) {
                break;
            }
        }
//        cerr << endl;
        ans[i] = t - 1;
    }
    for (int i = 1; i <= (1 << n); i++) {
        cout << ans[i] << " ";
    }

//    int n, m;
//    cin >> n >> m;
//
//
//    vector<vector<int>> ans((1 << n) + 1);
//    int now = 2;
//    int t = 0;
//
//    for (int i = 1; i <= (1 << n); i++) {
//        ans[i].emplace_back(0);
////        cerr << i << endl;
//        if (i == now) {
//            now *= 2;
//            t++;
//        }
//        for (int j = 1; j <= t; j++) {
//            if (((i - 1) >> (j - 1)) & 1) {
////                if (ans[i].empty())
//                ans[i].back() = j;
//            } else {
//                ans[i].emplace_back(j);
//            }
//        }
//    }
//    for (int i = 0; i < (1 << n); i++) {
//        int x;
//        cin >> x;
//        int t = min<int>(m, ans[x].size() - 1);
//        cout << ans[x][t]<<" ";
//    }

}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }

}#include "bits/stdc++.h"

using namespace std;


class FIW {
    int n;
    vector<int> fiw;
public:
    FIW(int n) : n(n), fiw(n + 1) {

    }

    void add(int pos, int t) {
        while (pos <= n) {
            fiw[pos] += t;
            pos += pos & (-pos);
        }
    }

    int query(int pos) {
        int res = 0;
        while (pos) {
            res += fiw[pos];
            pos -= pos & (-pos);
        }
        return res;
    }

    int sum(int l, int r) {
        return query(r) - query(l - 1);
    }
};

void solve() {
    int n, m;
    cin >> n >> m;
    FIW fiw((1 << n) + 1);

    vector<int> arr((1 << n) + 1);
    vector<int> que((1 << n));
    iota(que.begin(), que.end(), 1);

    vector<int> ans((1 << n) + 1);
    for (int i = 1; i <= (1 << n); i++) {
        cin >> arr[i];
//        arr[i] = i;
    }
    sort(que.begin(), que.end(), [&](int a, int b) {
        return arr[a] < arr[b];
    });
    for (auto i: que) {
        fiw.add(i, 1);
        int l = i, r = i;
        int nums = arr[i];
        int t = 0;

//        cerr << "[" << i << "]\n";
        while (true) {

            int k = ((l - 1) >> t) & 1;
            if (k) {
                l -= 1 << t;
            } else {
                r += 1 << t;
            }
//            cerr << l << " " << r << endl;
            t++;
//            cerr << r - l + 1 << " " << fiw.sum(l, r) << " " << m << " " << (r - l + 1) - fiw.sum(l, r) << " " <<(  (r - l + 1) - fiw.sum(l, r) > m)<< endl;
            if (r - l + 1 > nums || (r - l + 1) - fiw.sum(l, r) > m) {
                break;
            }
        }
//        cerr << endl;
        ans[i] = t - 1;
    }
    for (int i = 1; i <= (1 << n); i++) {
        cout << ans[i] << " ";
    }

//    int n, m;
//    cin >> n >> m;
//
//
//    vector<vector<int>> ans((1 << n) + 1);
//    int now = 2;
//    int t = 0;
//
//    for (int i = 1; i <= (1 << n); i++) {
//        ans[i].emplace_back(0);
////        cerr << i << endl;
//        if (i == now) {
//            now *= 2;
//            t++;
//        }
//        for (int j = 1; j <= t; j++) {
//            if (((i - 1) >> (j - 1)) & 1) {
////                if (ans[i].empty())
//                ans[i].back() = j;
//            } else {
//                ans[i].emplace_back(j);
//            }
//        }
//    }
//    for (int i = 0; i < (1 << n); i++) {
//        int x;
//        cin >> x;
//        int t = min<int>(m, ans[x].size() - 1);
//        cout << ans[x][t]<<" ";
//    }

}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }

}

Details

answer.code:122:2: error: stray ‘#’ in program
  122 | }#include "bits/stdc++.h"
      |  ^
answer.code:122:3: error: ‘include’ does not name a type
  122 | }#include "bits/stdc++.h"
      |   ^~~~~~~
answer.code:127:7: error: redefinition of ‘class FIW’
  127 | class FIW {
      |       ^~~
answer.code:6:7: note: previous definition of ‘class FIW’
    6 | class FIW {
      |       ^~~
answer.code:156:6: error: redefinition of ‘void solve()’
  156 | void solve() {
      |      ^~~~~
answer.code:35:6: note: ‘void solve()’ previously defined here
   35 | void solve() {
      |      ^~~~~
answer.code:235:5: error: redefinition of ‘int main()’
  235 | int main() {
      |     ^~~~
answer.code:114:5: note: ‘int main()’ previously defined here
  114 | int main() {
      |     ^~~~