QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#448307 | #8685. Doing the Container Shuffle | james1BadCreeper# | AC ✓ | 93ms | 11736kb | C++17 | 764b | 2024-06-19 15:21:20 | 2024-06-19 15:21:20 |
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 - F.sum(min(u, v));
}
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: 3868kb
input:
1 1
output:
1.00000
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
11 5 9 1 3 11 10 2 4 6 8 7
output:
31.50000
result:
ok found '31.50000', expected '31.50000', error '0.00000'
Test #3:
score: 0
Accepted
time: 71ms
memory: 11684kb
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.00000
result:
ok found '250000750000.00000', expected '250000750000.00000', error '0.00000'
Test #4:
score: 0
Accepted
time: 65ms
memory: 11728kb
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.00000
result:
ok found '1000000.00000', expected '1000000.00000', error '0.00000'
Test #5:
score: 0
Accepted
time: 72ms
memory: 11728kb
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:
250000250000.50000
result:
ok found '250000250000.50000', expected '250000250000.50000', error '0.00000'
Test #6:
score: 0
Accepted
time: 93ms
memory: 11736kb
input:
994035 501373 247446 988466 937134 343835 973148 182415 951866 745865 339379 898937 664973 414939 497080 565725 595547 866210 838583 1781 170429 231711 725020 700441 244760 764648 903161 47032 657141 341312 19655 564907 809801 365122 716028 737378 344047 876468 285811 642071 250280 125260 431866 471...
output:
164630427617.50000
result:
ok found '164630427617.50000', expected '164630427617.50000', error '0.00000'
Test #7:
score: 0
Accepted
time: 86ms
memory: 11592kb
input:
990577 319151 990109 386981 458867 837995 238010 339168 3601 487855 247241 31467 247761 126854 472633 167808 316914 429050 605798 437031 792795 522666 316627 126071 730410 904464 145293 433549 16684 768650 71832 815538 687489 190661 503739 596590 962984 352360 530342 741527 98472 784959 723314 79978...
output:
163590360586.00000
result:
ok found '163590360586.00000', expected '163590360586.00000', error '0.00000'
Test #8:
score: 0
Accepted
time: 85ms
memory: 11576kb
input:
990623 1 2 3 4 5 6 7 9 10 12 13 15 16 17 19 21 24 26 30 32 33 35 36 37 38 39 41 42 43 44 46 48 49 50 51 52 54 56 57 58 59 61 62 65 66 67 69 70 71 74 75 77 80 81 82 83 85 87 88 89 90 91 92 94 96 100 103 106 108 109 110 111 112 113 114 115 116 117 119 120 121 122 123 124 125 129 130 131 132 134 135 13...
output:
181710269146.00000
result:
ok found '181710269146.00000', expected '181710269146.00000', error '0.00000'
Test #9:
score: 0
Accepted
time: 86ms
memory: 11588kb
input:
991684 991684 991683 991682 991680 991679 991678 991677 991676 991674 991673 991671 991670 991669 991668 991666 991665 991664 991662 991661 991660 991659 991658 991656 991655 991654 991651 991650 991646 991644 991643 991642 991641 991639 991638 991637 991635 991634 991633 991632 991628 991626 991625...
output:
72935001476.00000
result:
ok found '72935001476.00000', expected '72935001476.00000', error '0.00000'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
2 1 2
output:
2.50000
result:
ok found '2.50000', expected '2.50000', error '0.00000'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3824kb
input:
2 2 1
output:
2.00000
result:
ok found '2.00000', expected '2.00000', error '0.00000'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
3 1 2 3
output:
4.50000
result:
ok found '4.50000', expected '4.50000', error '0.00000'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
3 1 3 2
output:
4.50000
result:
ok found '4.50000', expected '4.50000', error '0.00000'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3924kb
input:
3 2 1 3
output:
4.00000
result:
ok found '4.00000', expected '4.00000', error '0.00000'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3 2 3 1
output:
3.50000
result:
ok found '3.50000', expected '3.50000', error '0.00000'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
3 3 1 2
output:
3.50000
result:
ok found '3.50000', expected '3.50000', error '0.00000'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
3 3 2 1
output:
3.00000
result:
ok found '3.00000', expected '3.00000', error '0.00000'
Test #18:
score: 0
Accepted
time: 1ms
memory: 3912kb
input:
4 1 2 3 4
output:
7.00000
result:
ok found '7.00000', expected '7.00000', error '0.00000'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
4 4 3 2 1
output:
4.00000
result:
ok found '4.00000', expected '4.00000', error '0.00000'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3908kb
input:
4 2 3 4 1
output:
5.50000
result:
ok found '5.50000', expected '5.50000', error '0.00000'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
10 1 3 5 7 9 2 4 6 8 10
output:
29.50000
result:
ok found '29.50000', expected '29.50000', error '0.00000'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
10 10 8 6 4 2 1 3 5 7 9
output:
20.00000
result:
ok found '20.00000', expected '20.00000', error '0.00000'
Test #23:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
100 90 76 96 2 19 32 25 16 14 5 80 72 52 10 41 94 75 11 73 85 42 31 30 28 69 9 60 29 6 93 1 43 97 54 47 34 7 95 22 39 57 12 15 51 26 33 20 53 82 74 24 59 3 62 55 45 71 64 35 17 77 79 50 61 18 100 89 68 44 4 40 84 48 78 98 49 8 23 83 63 91 38 65 46 27 56 92 67 58 88 66 87 81 86 21 13 36 37 99 70
output:
1905.00000
result:
ok found '1905.00000', expected '1905.00000', error '0.00000'
Test #24:
score: 0
Accepted
time: 1ms
memory: 3852kb
input:
1000 536 844 931 150 719 434 698 95 224 485 118 759 113 852 362 251 493 185 927 939 949 328 359 554 317 46 591 630 763 877 722 775 675 173 954 815 24 625 547 544 230 689 956 142 944 87 151 285 900 616 540 771 901 398 864 429 818 126 738 450 740 825 670 809 353 581 269 936 146 12 752 505 139 545 364 ...
output:
167358.50000
result:
ok found '167358.50000', expected '167358.50000', error '0.00000'
Test #25:
score: 0
Accepted
time: 2ms
memory: 3848kb
input:
10000 3121 5398 7502 7133 2730 4786 9279 968 6950 9938 206 2976 7705 313 171 5770 3278 509 4011 5358 9301 3857 88 3260 3728 30 7258 251 5519 132 5960 3815 7638 8574 5645 6593 6996 1531 6532 1425 3001 6770 8591 9440 1908 1956 1480 9453 4260 4176 4335 8469 8987 6592 8829 4279 5290 5004 2200 1012 2859 ...
output:
16657203.00000
result:
ok found '16657203.00000', expected '16657203.00000', error '0.00000'
Test #26:
score: 0
Accepted
time: 9ms
memory: 4704kb
input:
100000 73766 90001 97450 82800 12572 40005 17755 62280 17053 49546 35716 92236 15667 72056 63775 39360 912 43582 67293 41298 82840 35311 78525 54385 64298 94640 17530 32052 35721 52679 51406 9347 77404 45655 38543 85594 35458 96799 20259 81626 27124 61778 63240 87760 60303 89782 71337 28741 12499 26...
output:
1666906476.00000
result:
ok found '1666906476.00000', expected '1666906476.00000', error '0.00000'
Extra Test:
score: 0
Extra Test Passed