Task: | Sorting books |
Sender: | aalto2024d_004 |
Submission time: | 2024-09-25 17:00:14 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.00 s | details |
#17 | ACCEPTED | 0.00 s | details |
#18 | ACCEPTED | 0.00 s | details |
#19 | ACCEPTED | 0.00 s | details |
#20 | ACCEPTED | 0.00 s | details |
#21 | ACCEPTED | 0.00 s | details |
#22 | ACCEPTED | 0.00 s | details |
#23 | ACCEPTED | 0.00 s | details |
#24 | ACCEPTED | 0.00 s | details |
#25 | ACCEPTED | 0.00 s | details |
#26 | ACCEPTED | 0.00 s | details |
#27 | ACCEPTED | 0.00 s | details |
#28 | ACCEPTED | 0.00 s | details |
#29 | ACCEPTED | 0.00 s | details |
#30 | ACCEPTED | 0.00 s | details |
#31 | ACCEPTED | 0.00 s | details |
#32 | ACCEPTED | 0.00 s | details |
#33 | ACCEPTED | 0.00 s | details |
#34 | ACCEPTED | 0.00 s | details |
#35 | ACCEPTED | 0.00 s | details |
#36 | ACCEPTED | 0.00 s | details |
#37 | ACCEPTED | 0.00 s | details |
#38 | ACCEPTED | 0.00 s | details |
#39 | ACCEPTED | 0.00 s | details |
#40 | ACCEPTED | 0.00 s | details |
#41 | ACCEPTED | 0.00 s | details |
#42 | ACCEPTED | 0.00 s | details |
#43 | ACCEPTED | 0.00 s | details |
#44 | ACCEPTED | 0.00 s | details |
#45 | ACCEPTED | 0.00 s | details |
#46 | ACCEPTED | 0.00 s | details |
#47 | ACCEPTED | 0.00 s | details |
#48 | ACCEPTED | 0.00 s | details |
#49 | ACCEPTED | 0.00 s | details |
#50 | ACCEPTED | 0.00 s | details |
#51 | ACCEPTED | 0.00 s | details |
#52 | ACCEPTED | 0.00 s | details |
#53 | ACCEPTED | 0.00 s | details |
#54 | ACCEPTED | 0.00 s | details |
#55 | ACCEPTED | 0.00 s | details |
#56 | ACCEPTED | 0.00 s | details |
#57 | ACCEPTED | 0.00 s | details |
#58 | ACCEPTED | 0.00 s | details |
#59 | ACCEPTED | 0.00 s | details |
#60 | ACCEPTED | 0.00 s | details |
#61 | ACCEPTED | 0.10 s | details |
#62 | ACCEPTED | 0.10 s | details |
#63 | ACCEPTED | 0.10 s | details |
#64 | ACCEPTED | 0.10 s | details |
#65 | ACCEPTED | 0.10 s | details |
#66 | ACCEPTED | 0.10 s | details |
#67 | ACCEPTED | 0.10 s | details |
#68 | ACCEPTED | 0.10 s | details |
#69 | ACCEPTED | 0.10 s | details |
#70 | ACCEPTED | 0.10 s | details |
#71 | ACCEPTED | 0.04 s | details |
Code
#include <bits/stdc++.h> using namespace std; #define int long long string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif const int N = 2e5 + 5; int n, a[N]; vector<int> v; int bit[N]; void upd(int u, int v) { for (int i = u; i <= 2e5; i += i & -i) { bit[i] += v; } } int get(int u) { int ans = 0; for (int i = u; i >= 1; i -= i & -i) { ans += bit[i]; } return ans; } signed main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; v.push_back(a[i]); } sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); int ans = 0; for (int i = 1; i <= n; i++) { int val = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1; ans += get(2e5) - get(val); upd(val, 1); } cout << ans << '\n'; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 1 |
correct output |
---|
0 |
user output |
---|
0 |
Test 2
Verdict: ACCEPTED
input |
---|
2 3 7 |
correct output |
---|
0 |
user output |
---|
0 |
Test 3
Verdict: ACCEPTED
input |
---|
2 3 6 |
correct output |
---|
0 |
user output |
---|
0 |
Test 4
Verdict: ACCEPTED
input |
---|
2 3 8 |
correct output |
---|
0 |
user output |
---|
0 |
Test 5
Verdict: ACCEPTED
input |
---|
3 1 2 10 |
correct output |
---|
0 |
user output |
---|
0 |
Test 6
Verdict: ACCEPTED
input |
---|
3 3 7 10 |
correct output |
---|
0 |
user output |
---|
0 |
Test 7
Verdict: ACCEPTED
input |
---|
3 3 6 8 |
correct output |
---|
0 |
user output |
---|
0 |
Test 8
Verdict: ACCEPTED
input |
---|
4 5 5 4 10 |
correct output |
---|
2 |
user output |
---|
2 |
Test 9
Verdict: ACCEPTED
input |
---|
4 4 5 5 5 |
correct output |
---|
0 |
user output |
---|
0 |
Test 10
Verdict: ACCEPTED
input |
---|
4 7 10 7 1 |
correct output |
---|
4 |
user output |
---|
4 |
Test 11
Verdict: ACCEPTED
input |
---|
5 6 6 8 9 7 |
correct output |
---|
2 |
user output |
---|
2 |
Test 12
Verdict: ACCEPTED
input |
---|
5 5 10 8 10 1 |
correct output |
---|
5 |
user output |
---|
5 |
Test 13
Verdict: ACCEPTED
input |
---|
5 5 2 1 10 6 |
correct output |
---|
4 |
user output |
---|
4 |
Test 14
Verdict: ACCEPTED
input |
---|
5 6 1 8 9 3 |
correct output |
---|
4 |
user output |
---|
4 |
Test 15
Verdict: ACCEPTED
input |
---|
5 10 10 6 2 10 |
correct output |
---|
5 |
user output |
---|
5 |
Test 16
Verdict: ACCEPTED
input |
---|
5 3 1 9 9 3 |
correct output |
---|
3 |
user output |
---|
3 |
Test 17
Verdict: ACCEPTED
input |
---|
5 9 10 4 3 9 |
correct output |
---|
6 |
user output |
---|
6 |
Test 18
Verdict: ACCEPTED
input |
---|
5 1 3 8 4 5 |
correct output |
---|
2 |
user output |
---|
2 |
Test 19
Verdict: ACCEPTED
input |
---|
5 9 1 10 3 9 |
correct output |
---|
4 |
user output |
---|
4 |
Test 20
Verdict: ACCEPTED
input |
---|
5 1 4 6 5 5 |
correct output |
---|
2 |
user output |
---|
2 |
Test 21
Verdict: ACCEPTED
input |
---|
10 6 6 8 9 7 9 6 9 5 7 |
correct output |
---|
18 |
user output |
---|
18 |
Test 22
Verdict: ACCEPTED
input |
---|
10 5 10 8 10 1 2 4 10 2 3 |
correct output |
---|
25 |
user output |
---|
25 |
Test 23
Verdict: ACCEPTED
input |
---|
10 5 2 1 10 6 10 5 5 5 4 |
correct output |
---|
20 |
user output |
---|
20 |
Test 24
Verdict: ACCEPTED
input |
---|
10 6 1 8 9 3 2 6 6 9 5 |
correct output |
---|
18 |
user output |
---|
18 |
Test 25
Verdict: ACCEPTED
input |
---|
10 10 10 6 2 10 9 8 7 7 6 |
correct output |
---|
29 |
user output |
---|
29 |
Test 26
Verdict: ACCEPTED
input |
---|
10 3 1 9 9 3 4 10 10 5 1 |
correct output |
---|
17 |
user output |
---|
17 |
Test 27
Verdict: ACCEPTED
input |
---|
10 9 10 4 3 9 1 1 4 2 10 |
correct output |
---|
25 |
user output |
---|
25 |
Test 28
Verdict: ACCEPTED
input |
---|
10 1 3 8 4 5 10 8 5 10 4 |
correct output |
---|
12 |
user output |
---|
12 |
Test 29
Verdict: ACCEPTED
input |
---|
10 9 1 10 3 9 4 6 9 3 5 |
correct output |
---|
22 |
user output |
---|
22 |
Test 30
Verdict: ACCEPTED
input |
---|
10 1 4 6 5 5 1 2 4 2 1 |
correct output |
---|
25 |
user output |
---|
25 |
Test 31
Verdict: ACCEPTED
input |
---|
100 589284012 636562060 767928734 ... |
correct output |
---|
2843 |
user output |
---|
2843 |
Test 32
Verdict: ACCEPTED
input |
---|
100 447773962 773442532 122816 137... |
correct output |
---|
2446 |
user output |
---|
2446 |
Test 33
Verdict: ACCEPTED
input |
---|
100 468145963 198730372 27838076 5... |
correct output |
---|
2158 |
user output |
---|
2158 |
Test 34
Verdict: ACCEPTED
input |
---|
100 591414747 75940263 760367935 9... |
correct output |
---|
2298 |
user output |
---|
2298 |
Test 35
Verdict: ACCEPTED
input |
---|
100 967034924 587586158 185430194 ... |
correct output |
---|
2580 |
user output |
---|
2580 |
Test 36
Verdict: ACCEPTED
input |
---|
100 238363353 59249204 934941692 8... |
correct output |
---|
2578 |
user output |
---|
2578 |
Test 37
Verdict: ACCEPTED
input |
---|
100 958701283 356460601 224848374 ... |
correct output |
---|
2417 |
user output |
---|
2417 |
Test 38
Verdict: ACCEPTED
input |
---|
100 81935404 244103474 837431431 3... |
correct output |
---|
2315 |
user output |
---|
2315 |
Test 39
Verdict: ACCEPTED
input |
---|
100 937837681 11934038 257096283 9... |
correct output |
---|
2692 |
user output |
---|
2692 |
Test 40
Verdict: ACCEPTED
input |
---|
100 11139168 391337048 538883744 5... |
correct output |
---|
2302 |
user output |
---|
2302 |
Test 41
Verdict: ACCEPTED
input |
---|
200 589284012 636562060 767928734 ... |
correct output |
---|
10624 |
user output |
---|
10624 |
Test 42
Verdict: ACCEPTED
input |
---|
200 447773962 773442532 122816 137... |
correct output |
---|
9384 |
user output |
---|
9384 |
Test 43
Verdict: ACCEPTED
input |
---|
200 468145963 198730372 27838076 5... |
correct output |
---|
8760 |
user output |
---|
8760 |
Test 44
Verdict: ACCEPTED
input |
---|
200 591414747 75940263 760367935 9... |
correct output |
---|
8939 |
user output |
---|
8939 |
Test 45
Verdict: ACCEPTED
input |
---|
200 967034924 587586158 185430194 ... |
correct output |
---|
9905 |
user output |
---|
9905 |
Test 46
Verdict: ACCEPTED
input |
---|
200 238363353 59249204 934941692 8... |
correct output |
---|
9851 |
user output |
---|
9851 |
Test 47
Verdict: ACCEPTED
input |
---|
200 958701283 356460601 224848374 ... |
correct output |
---|
10551 |
user output |
---|
10551 |
Test 48
Verdict: ACCEPTED
input |
---|
200 81935404 244103474 837431431 3... |
correct output |
---|
9163 |
user output |
---|
9163 |
Test 49
Verdict: ACCEPTED
input |
---|
200 937837681 11934038 257096283 9... |
correct output |
---|
9346 |
user output |
---|
9346 |
Test 50
Verdict: ACCEPTED
input |
---|
200 11139168 391337048 538883744 5... |
correct output |
---|
9982 |
user output |
---|
9982 |
Test 51
Verdict: ACCEPTED
input |
---|
1000 589284012 636562060 767928734 ... |
correct output |
---|
256701 |
user output |
---|
256701 |
Test 52
Verdict: ACCEPTED
input |
---|
1000 447773962 773442532 122816 137... |
correct output |
---|
243505 |
user output |
---|
243505 |
Test 53
Verdict: ACCEPTED
input |
---|
1000 468145963 198730372 27838076 5... |
correct output |
---|
252964 |
user output |
---|
252964 |
Test 54
Verdict: ACCEPTED
input |
---|
1000 591414747 75940263 760367935 9... |
correct output |
---|
246581 |
user output |
---|
246581 |
Test 55
Verdict: ACCEPTED
input |
---|
1000 967034924 587586158 185430194 ... |
correct output |
---|
241203 |
user output |
---|
241203 |
Test 56
Verdict: ACCEPTED
input |
---|
1000 238363353 59249204 934941692 8... |
correct output |
---|
251093 |
user output |
---|
251093 |
Test 57
Verdict: ACCEPTED
input |
---|
1000 958701283 356460601 224848374 ... |
correct output |
---|
256962 |
user output |
---|
256962 |
Test 58
Verdict: ACCEPTED
input |
---|
1000 81935404 244103474 837431431 3... |
correct output |
---|
250165 |
user output |
---|
250165 |
Test 59
Verdict: ACCEPTED
input |
---|
1000 937837681 11934038 257096283 9... |
correct output |
---|
246466 |
user output |
---|
246466 |
Test 60
Verdict: ACCEPTED
input |
---|
1000 11139168 391337048 538883744 5... |
correct output |
---|
249076 |
user output |
---|
249076 |
Test 61
Verdict: ACCEPTED
input |
---|
200000 589284012 636562060 767928734 ... |
correct output |
---|
9983154934 |
user output |
---|
9983154934 |
Test 62
Verdict: ACCEPTED
input |
---|
200000 447773962 773442532 122816 137... |
correct output |
---|
9998885834 |
user output |
---|
9998885834 |
Test 63
Verdict: ACCEPTED
input |
---|
200000 468145963 198730372 27838076 5... |
correct output |
---|
9995310844 |
user output |
---|
9995310844 |
Test 64
Verdict: ACCEPTED
input |
---|
200000 591414747 75940263 760367935 9... |
correct output |
---|
10000936270 |
user output |
---|
10000936270 |
Test 65
Verdict: ACCEPTED
input |
---|
200000 967034924 587586158 185430194 ... |
correct output |
---|
10002145347 |
user output |
---|
10002145347 |
Test 66
Verdict: ACCEPTED
input |
---|
200000 238363353 59249204 934941692 8... |
correct output |
---|
9989708150 |
user output |
---|
9989708150 |
Test 67
Verdict: ACCEPTED
input |
---|
200000 958701283 356460601 224848374 ... |
correct output |
---|
9997845631 |
user output |
---|
9997845631 |
Test 68
Verdict: ACCEPTED
input |
---|
200000 81935404 244103474 837431431 3... |
correct output |
---|
10016175198 |
user output |
---|
10016175198 |
Test 69
Verdict: ACCEPTED
input |
---|
200000 937837681 11934038 257096283 9... |
correct output |
---|
9983428867 |
user output |
---|
9983428867 |
Test 70
Verdict: ACCEPTED
input |
---|
200000 11139168 391337048 538883744 5... |
correct output |
---|
9971613818 |
user output |
---|
9971613818 |
Test 71
Verdict: ACCEPTED
input |
---|
200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
0 |
user output |
---|
0 |