QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#692366#6431. Oops, It's Yesterday Twice MoreRegistrationError#TL 0ms0kbC++201.7kb2024-10-31 14:23:552024-10-31 14:23:57

Judging History

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

  • [2024-10-31 14:23:57]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-31 14:23:55]
  • 提交

answer

#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define sz(a) (int) (a).size()
#define int long long
using namespace std;

vector<int> brute(int n, const vector<int>& a) {
    vector<int> ans;
    for (int pf = 1; pf <= n; pf++) {
        vector<int> b(a.begin(), a.begin() + pf);
        int cnt = 0;
        for (int i = 0; i < pf; i++) {
            for (int j = 0; j < pf; j++) {
                if (b[i] < b[j]) {
                    swap(b[i], b[j]);
                    cnt++;
                }
            }
        }
        ans.push_back(cnt);
    }
    return ans;
}

const int N = 1e5 + 11;

struct BIT{
    int bit[N];
    void add(int p, int v) {
        for (int i = p; i < N; i += i & -i) {
            bit[i] += v;
        }
    }
    int qry(int p) {
        int res = 0;
        for (int i = p; i; i -= i & -i) {
            res += bit[i];
        }
        return res;
    }
} bit;

vector<int> calc(int n, const vector<int>& a) {
    vector<int> ans(n);
    int inv = 0, num_eq = 0, cur_max = 0;
    for (int i = 0; i < n; i++) {
        bit.add(a[i], 1);
        inv += bit.qry(a[i] - 1);
        if (a[i] == cur_max) num_eq++;
        else if (a[i] > cur_max) cur_max = a[i];
        ans[i] = inv + num_eq;
    }
    for (int i = 0; i < n; i++) {
        bit.add(a[i], -1);
    }
    return ans;
}

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<int> ans = calc(n, a);
    
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " \n"[i == n - 1];
    }
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(false);

    int t = 1; cin >> t;
    while (t--) {
        solve();
    }
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

3 3 3

output:


result: