# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199365 | arnold518 | 즐거운 채소 기르기 (JOI14_growing) | C++14 | 31 ms | 6772 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 3e5;
int N, A[MAXN+10];
ll L[MAXN+10], R[MAXN+10];
vector<int> comp;
int getcomp(int x) { return lower_bound(comp.begin(), comp.end(), x)-comp.begin()+1; }
struct BIT
{
ll tree[MAXN+10];
BIT() { memset(tree, 0, sizeof(tree)); }
void update(int i) { for(; i<=N; i+=(i&-i)) tree[i]++; }
ll query(int i) { ll ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; }
} bit;
int main()
{
int i, j;
scanf("%d", &N);
for(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(i=1; i<=N; i++) A[i]=getcomp(A[i]);
bit=BIT();
for(i=1; i<=N; i++)
{
L[i]=L[i-1]+bit.query(N)-bit.query(A[i]);
bit.update(A[i]);
}
bit=BIT();
for(i=N; i>=1; i--)
{
R[i]=R[i+1]+bit.query(N)-bit.query(A[i]);
bit.update(A[i]);
}
ll ans=1e18;
for(i=0; i<=N; i++) ans=min(ans, L[i]+R[i+1]);
printf("%lld", 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... |