# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
25798 | kdh9949 | 즐거운 채소 기르기 (JOI14_growing) | C++14 | 153 ms | 5536 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (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... |