Skip to content

Commit 01a944d

Browse files
committedMay 16, 2022
lotsastuff
1 parent c336b23 commit 01a944d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+5317
-20
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
// incomplete
4+
#define rep(i, a, b) for(int i = a; i < (b); ++i)
5+
#define all(x) begin(x), end(x)
6+
#define sz(x) (int)(x).size()
7+
typedef long long ll;
8+
typedef pair<int, int> pii;
9+
typedef vector<int> vi;
10+
typedef vector<ll> vll;
11+
typedef complex<double> cd;
12+
13+
int main() {
14+
ios_base::sync_with_stdio(false);
15+
cin.tie(NULL);
16+
int n, m;
17+
cin >> n >> m;
18+
rep(i,0,m){
19+
int a, b;
20+
cin >> a >> b;
21+
if (b < a) swap(a, b);
22+
cout << a << " " << b << endl;
23+
}
24+
}
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
#include <ext/pb_ds/assoc_container.hpp>
3+
#include <ext/pb_ds/tree_policy.hpp>
4+
using namespace std;
5+
using namespace __gnu_pbds;
6+
// incomplete
7+
#define rep(i, a, b) for(int i = a; i < (b); ++i)
8+
#define all(x) begin(x), end(x)
9+
#define sz(x) (int)(x).size()
10+
typedef long long ll;
11+
typedef pair<int, int> pii;
12+
typedef vector<int> vi;
13+
typedef vector<ll> vll;
14+
typedef complex<double> cd;
15+
16+
tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OS;
17+
// Supports .order_of_key(x), counts number of elements less than x.
18+
// Supports .find_by_order(n), returns iterator to nth element (0-indexed)
19+
20+
int main() {
21+
ios_base::sync_with_stdio(false);
22+
cin.tie(NULL);
23+
int n;
24+
cin >> n;
25+
vector<pii> a;
26+
rep(i,0,n){
27+
int b;
28+
cin >> b;
29+
a.push_back({b, i});
30+
OS.insert(i);
31+
}
32+
sort(all(a));
33+
ll tot = 0;
34+
rep(i,0,n){
35+
int id = OS.order_of_key(a[i].second);
36+
// cout << i << " " << min(n-i-1-id, id) << endl;
37+
tot += min(n-i-1-id,id);
38+
OS.erase(a[i].second);
39+
}
40+
cout << tot << endl;
41+
}

0 commit comments

Comments
 (0)
Please sign in to comment.