-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path112.cpp
More file actions
42 lines (35 loc) · 817 Bytes
/
Copy path112.cpp
File metadata and controls
42 lines (35 loc) · 817 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int bit_tree[10005];
int n;
void add(int idx, int val) {
for (; idx <= n; idx += idx & -idx) {
bit_tree[idx] += val;
}
}
int query(int idx) {
int sum = 0;
for (; idx > 0; idx -= idx & -idx) {
sum += bit_tree[idx];
}
return sum;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int k;
if (cin >> n >> k) {
long long total_pushups = 0;
for (int r = 0; r < k; ++r) {
memset(bit_tree, 0, sizeof(bit_tree));
for (int i = 0; i < n; ++i) {
int height;
cin >> height;
total_pushups += i - query(height);
add(height, 1);
}
}
cout << total_pushups << "\n";
}
return 0;
}