mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:28:47 +00:00
parent
8dbd7b2da0
commit
3ecf91301d
49
S2OJ/137/137.cpp
Normal file
49
S2OJ/137/137.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 3e5 + 5;
|
||||
|
||||
int n, a[N], c1[N], c2[N], ans[N];
|
||||
|
||||
int lowbit(int x) {
|
||||
return x & -x;
|
||||
}
|
||||
|
||||
void add(int* c, int x, int y) {
|
||||
for (; x <= n; x += lowbit(x)) c[x] += y;
|
||||
}
|
||||
|
||||
int sum(int* c, int x) {
|
||||
int res = 0;
|
||||
for (; x; x -= lowbit(x)) res += c[x];
|
||||
return res;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
ans[i] = sum(c1, n) - sum(c1, a[i]);
|
||||
add(c1, a[i], 1);
|
||||
}
|
||||
|
||||
for (int i = n; i; i--) {
|
||||
ans[i] = std::min(ans[i], sum(c2, n) - sum(c2, a[i]));
|
||||
add(c2, a[i], 1);
|
||||
}
|
||||
|
||||
cout << std::accumulate(ans + 1, ans + 1 + n, 0ll) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/137/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy1.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy1.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy10.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy10.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy11.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy11.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy11.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy12.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy12.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy12.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy13.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy13.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy13.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy14.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy14.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy14.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy15.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy15.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy15.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy16.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy16.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy16.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy17.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy17.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy17.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy18.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy18.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy18.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy19.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy19.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy19.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy2.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy2.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy20.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy20.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy20.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy3.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy3.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy4.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy4.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy5.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy5.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy6.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy6.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy7.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy7.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy8.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy8.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy9.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy9.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/137/data/psy9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/137/data/psy9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user