QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#426252 | #8685. Doing the Container Shuffle | UFRJ | WA | 0ms | 3616kb | C++23 | 1.3kb | 2024-05-31 00:56:45 | 2024-05-31 00:56:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using lint = int64_t;
const int mod = 998244353;
template<typename T> struct FT {
vector<T> s;
FT(int n) : s(n) {}
FT(const vector<T>& A) : s(A) {
const int N = int(s.size());
for (int a = 0; a < N; ++a)
if ((a | (a + 1)) < N) s[a | (a + 1)] += s[a];
}
void update(int pos, T dif) { // a[pos] += dif
for (; pos < (int)s.size(); pos |= pos + 1) s[pos] += dif;
}
T query(int pos) { // sum of values in [0, pos)
T res = 0;
for (; pos > 0; pos &= pos - 1) res += s[pos-1];
return res;
}
// min pos st sum of [0, pos] >= sum. Returns n if no sum
int lower_bound(T sum) { //is >= sum, or -1 if empty sum is.
if (sum <= 0) return -1;
int pos = 0;
for (int pw = 1 << 25; pw; pw >>= 1)
if (pos + pw <= (int)s.size() && s[pos + pw-1] < sum)
pos += pw, sum -= s[pos-1];
return pos;
}
};
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++) cin>>a[i], a[i]--;
FT<int>seg(vector<int>(n, 1));
lint ans = 0;
int mn = n;
for(int i=0;i<n;i++){
seg.update(a[i], -1);
mn = min(mn, a[i]);
ans += seg.query(n) - seg.query(mn);
}
ans += 2 * n;
cout<<ans/2;
if(ans&1) cout<<".5\n";
else cout<<".0\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
1 1
output:
1.0
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3616kb
input:
11 5 9 1 3 11 10 2 4 6 8 7
output:
34.5
result:
wrong answer 1st numbers differ - expected: '31.50000', found: '34.50000', error = '0.09524'