QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#448341#8685. Doing the Container Shufflejames1BadCreeper#WA 1ms5960kbC++17772b2024-06-19 15:35:192024-06-19 15:35:19

Judging History

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

  • [2024-06-19 15:35:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5960kb
  • [2024-06-19 15:35:19]
  • 提交

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;
}

详细

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'