QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#418798 | #8685. Doing the Container Shuffle | light_ink_dots | WA | 96ms | 70328kb | C++14 | 976b | 2024-05-23 15:49:45 | 2024-05-23 15:49:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
static const int maxn = 1000010;
static int n;
scanf("%d", &n);
static int a[maxn], r[maxn];
static vector<int> vec[maxn];
for (int i = 1; i <= n; i++) scanf("%d", a + i), r[a[i]] = i;
for (int i = 1; i <= n - 2; i++) vec[min(r[i], r[i + 1])].push_back(i + 2);
struct BIT {
int a[maxn];
inline void insert(const int p) {
for (int i = p; i; i -= i & -i) a[i]++;
return;
}
inline int query(const int p) {
int ret = 0;
for (int i = p; i <= n; i += i & -i) ret += a[i];
return ret;
}
};
static BIT t;
long long ans = (n * (n - 1ll) >> 1) + (n << 1) - (r[1] - 1);
for (int i = 1; i <= n; i++) {
for (int p : vec[i]) ans -= t.query(p);
t.insert(a[i]);
}
printf("%lld.%d\n", ans >> 1, ans & 1 ? 5 : 0);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 29684kb
input:
1 1
output:
1.0
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #2:
score: 0
Accepted
time: 4ms
memory: 30300kb
input:
11 5 9 1 3 11 10 2 4 6 8 7
output:
31.5
result:
ok found '31.50000', expected '31.50000', error '0.00000'
Test #3:
score: 0
Accepted
time: 89ms
memory: 70244kb
input:
1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
250000750000.0
result:
ok found '250000750000.00000', expected '250000750000.00000', error '0.00000'
Test #4:
score: 0
Accepted
time: 89ms
memory: 70328kb
input:
1000000 1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976 999975 999974 999973 999972 999971 999970 999969 999968 999967 999966 999965 999964 999963 999962 999961 999960 9999...
output:
1000000.0
result:
ok found '1000000.00000', expected '1000000.00000', error '0.00000'
Test #5:
score: -100
Wrong Answer
time: 96ms
memory: 70300kb
input:
1000000 1000000 1 999999 2 999998 3 999997 4 999996 5 999995 6 999994 7 999993 8 999992 9 999991 10 999990 11 999989 12 999988 13 999987 14 999986 15 999985 16 999984 17 999983 18 999982 19 999981 20 999980 21 999979 22 999978 23 999977 24 999976 25 999975 26 999974 27 999973 28 999972 29 999971 30 ...
output:
125000999999.5
result:
wrong answer 1st numbers differ - expected: '250000250000.50000', found: '125000999999.50000', error = '0.50000'