Task: | Turbo |
Sender: | untokarila |
Submission time: | 2019-07-29 17:36:30 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.01 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | ACCEPTED | 0.01 s | details |
#7 | ACCEPTED | 0.01 s | details |
#8 | ACCEPTED | 0.02 s | details |
#9 | ACCEPTED | 0.04 s | details |
#10 | ACCEPTED | 0.07 s | details |
Code
#include <iostream> #include <algorithm> #define F first #define S second using namespace std; int n, z = 1, fr[131078], fi[131078]; pair<int, int> d[101010]; void add(int k, int o, int *f){ for(; k<=z; k+=k&-k) f[k]+=o; } int sum(int k, int *f){ int s = 0; for(; k; k-=k&-k) s += f[k]; return s; } int main(){ cin >> n; while(z<n) z*=2; for(int i=1; i<=n; i++){ int x; cin >> x; d[i] = {x, i}; add(i, 1, fr); add(i, 1, fi); } sort(d+1, d+n+1); int s = -n; for(int i=1; s; i+=s){ int a = sum(i-1, fi); int b = sum(d[i].S-1, fr); cout << abs(a-b) << '\n'; add(d[i].S, -1, fr); add(i, -1, fi); if(s>0) s--; else s++; s = -s; } return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
5
4 3 2 1 ... |
correct output |
---|
3
0 2 1 0 |
user output |
---|
3 0 2 1 0 |
Test 2
Verdict: ACCEPTED
input |
---|
8
2 3 5 8 ... |
correct output |
---|
6
3 0 2 0 ... |
user output |
---|
6 3 0 2 0 ... |
Test 3
Verdict: ACCEPTED
input |
---|
10
6 2 4 1 ... |
correct output |
---|
3
3 1 3 2 ... |
user output |
---|
3 3 1 3 2 ... |
Test 4
Verdict: ACCEPTED
input |
---|
17
9 8 15 14 ... |
correct output |
---|
15
10 13 2 12 ... |
user output |
---|
15 10 13 2 12 ... |
Test 5
Verdict: ACCEPTED
input |
---|
33
19 11 16 33 ... |
correct output |
---|
30
28 12 25 3 ... |
user output |
---|
30 28 12 25 3 ... |
Test 6
Verdict: ACCEPTED
input |
---|
72
72 67 13 28 ... |
correct output |
---|
51
70 43 21 54 ... |
user output |
---|
51 70 43 21 54 ... Truncated |
Test 7
Verdict: ACCEPTED
input |
---|
95
52 58 78 80 ... |
correct output |
---|
49
58 81 80 76 ... |
user output |
---|
49 58 81 80 76 ... Truncated |
Test 8
Verdict: ACCEPTED
input |
---|
21224
21139 2725 3303 13148 ... |
correct output |
---|
13305
9764 18691 1254 7043 ... |
user output |
---|
13305 9764 18691 1254 7043 ... Truncated |
Test 9
Verdict: ACCEPTED
input |
---|
61370
35656 9205 5841 17303 ... |
correct output |
---|
56587
43741 48553 16182 4458 ... |
user output |
---|
56587 43741 48553 16182 4458 ... Truncated |
Test 10
Verdict: ACCEPTED
input |
---|
100000
80825 41163 35758 92141 ... |
correct output |
---|
8989
79515 58926 79542 62384 ... |
user output |
---|
8989 79515 58926 79542 62384 ... Truncated |