-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD1.cpp
50 lines (35 loc) · 834 Bytes
/
D1.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
void run_cases() {
int n, m;
cin >> n >> m;
int inconvenience = 0;
vector<int> a(m);
for(int i = 0; i < m; i++) {
cin >> a[i];
}
vector<pair<int,int>> order;
for(int i = 0; i < m; i++) {
order.emplace_back(a[i], -i);
}
sort(order.begin(), order.end());
vector<bool> seats(m, false);
for(auto [_, seat_id]: order) {
for(int i = 0; i < -seat_id; i++) {
if(seats[i]) {
inconvenience++;
}
}
seats[-seat_id] = true;
}
cout << inconvenience << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(nullptr);
int tests = 1;
cin >> tests;
for(int test = 1;test <= tests;test++) {
run_cases();
}
}