# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
123919 | songc | 즐거운 채소 기르기 (JOI14_growing) | C++14 | 152 ms | 9316 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int N;
int A[303030], L[303030], R[303030], T[303030];
vector<int> comp;
LL ans;
void update(int t){
while (t<=N){
T[t]++;
t += t & -t;
}
}
int read(int t){
int ret=0;
while (t){
ret += T[t];
t -= t & -t;
}
return ret;
}
int main(){
scanf("%d", &N);
for (int i=1; i<=N; i++) {
scanf("%d", &A[i]);
comp.push_back(A[i]);
}
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
for (int i=1; i<=N; i++) A[i] = lower_bound(comp.begin(), comp.end(), A[i]) - comp.begin() + 1;
for (int i=1; i<=N; i++){
L[i] = read(N)-read(A[i]);
update(A[i]);
}
memset(T, 0, sizeof T);
for (int i=N; i>=1; i--){
R[i] = read(N)-read(A[i]);
update(A[i]);
}
for (int i=1; i<=N; i++) ans += min(L[i], R[i]);
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (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... |