# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25798 | kdh9949 | 즐거운 채소 기르기 (JOI14_growing) | C++14 | 153 ms | 5536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Dat{
int x, i;
bool operator<(const Dat &oth) const {
return x < oth.x;
}
};
int n;
Dat a[300010];
ll ans;
struct BIT{
int dat[300010];
void upd(int x, int v){ for(; x <= n; x += x & -x) dat[x] += v; }
int get(int x){ int ret = 0; for(; x; x -= x & -x) ret += dat[x]; return ret; }
int get(int s, int e){ return get(e) - get(s - 1); }
} B;
int main(){
scanf("%d", &n);
for(int i = 1, x; i <= n; i++){
scanf("%d", &x);
B.upd(i, 1);
a[i] = {x, i};
}
sort(a + 1, a + n + 1);
for(int i = 1, j; i <= n; i = j){
for(j = i; j <= n && a[j].x == a[i].x; j++){
B.upd(a[j].i, -1);
}
for(int k = i; k < j; k++){
ans += min(B.get(1, a[k].i), B.get(a[k].i, n));
}
}
printf("%lld\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |