QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#692366 | #6431. Oops, It's Yesterday Twice More | RegistrationError# | TL | 0ms | 0kb | C++20 | 1.7kb | 2024-10-31 14:23:55 | 2024-10-31 14:23:57 |
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();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 3 3