QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#448341 | #8685. Doing the Container Shuffle | james1BadCreeper# | WA | 1ms | 5960kb | C++17 | 772b | 2024-06-19 15:35:19 | 2024-06-19 15:35:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 1e6 + 5;
int n;
int a[N];
struct Fenwick {
int C[N];
inline void add(int x, int k) { for (; x <= n; x += x & -x) C[x] += k; }
inline int sum(int x) { int r = 0; for (; x; x -= x & -x) r += C[x]; return r; }
} F;
int main(void) {
ios::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
// 需要求,期望更换栈顶次数
i64 ans = n - a[1]; F.add(a[n], 1);
for (int i = n - 1; i >= 1; --i) {
F.add(a[i], 1);
int u = a[i], v = a[i + 1];
ans += n - i + 1 - F.sum(min(u, v) - 1);
}
cout << fixed << setprecision(5) << ans * 0.5 + n << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5884kb
input:
1 1
output:
1.00000
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5960kb
input:
11 5 9 1 3 11 10 2 4 6 8 7
output:
41.50000
result:
wrong answer 1st numbers differ - expected: '31.50000', found: '41.50000', error = '0.31746'