Submission #6113

#TimeUsernameProblemLanguageResultExecution timeMemory
6113kriii즐거운 채소 기르기 (JOI14_growing)C++98
100 / 100
316 ms19888 KiB
#include <stdio.h> #include <map> using namespace std; int N,D[300030],L[300030],R[300030],B[300030],C; map<int, int> chk; int main() { scanf ("%d",&N); for (int i=0;i<N;i++) scanf ("%d",&D[i]), chk[D[i]] = 0; for (map<int,int>::iterator I = chk.begin(); I != chk.end(); I++) I->second = ++C; for (int i=0;i<N;i++) D[i] = chk[D[i]]; for (int i=0;i<N;i++){ L[i] = i; for (int x=D[i];x;x-=x&(-x)) L[i] -= B[x]; for (int x=D[i];x<=C;x+=x&(-x)) B[x]++; } for (int i=1;i<=C;i++) B[i] = 0; for (int i=N-1;i>=0;i--){ R[i] = N-1-i; for (int x=D[i];x;x-=x&(-x)) R[i] -= B[x]; for (int x=D[i];x<=C;x+=x&(-x)) B[x]++; } long long ans = 0; for (int i=0;i<N;i++) ans += L[i] < R[i] ? L[i] : R[i]; printf ("%lld\n",ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...