QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#168437#6434. Paimon SortingzlxFTHWA 2ms3584kbC++141.2kb2023-09-08 15:01:442023-09-08 15:01:44

Judging History

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

  • [2023-09-08 15:01:44]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3584kb
  • [2023-09-08 15:01:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

struct BIT {
  int n;
  vector<int> a;
  BIT(int n = 0) : n(n), a(n + 1, 0) {}
  void mdf(int x, int v) {
    for (int i = x + 1; i <= n; i += i & -i) {
      a[i] += v;
    }
  }
  int qry(int x) {
    if (x < 0 || x >= n) return 0;
    int res = 0;
    for (int i = x + 1; i; i -= i & -i) {
      res += a[i];
    }
    return res; 
  }
  int sum(int l, int r) {
    int res = qry(r);
    res -= qry(l - 1);
    return res;
  }
};

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  cout << 0 << " ";
  BIT t(n);
  vector<int> vis(n);
  auto cg = [&](int x) {
    if (!vis[x]) {
      t.mdf(x, 1);
    }
    vis[x]++;
  };
  cg(a[0]);
  for (int i = 1; i < n; i++) {
    int v = a[i];
    if (a[0] >= a[i]) {
      ans += t.sum(a[i] + 1, n - 1);
    } else {
      ans++;
      ans -= (i - 1) - (vis[a[0]] - 1);
      ans += i;
      swap(a[0], a[i]);
    }
    cg(v);
    cout << ans << " ";
  }
  cout << "\n";
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3584kb

input:

3
5
2 3 2 1 5
3
1 2 3
1
1

output:

0 2 3 5 7 
0 2 4 
0 

result:

wrong answer 1st lines differ - expected: '0 2 3 5 7', found: '0 2 3 5 7 '