Submission #10686

#TimeUsernameProblemLanguageResultExecution timeMemory
10686gs13068즐거운 채소 기르기 (JOI14_growing)C++98
0 / 100
12 ms4604 KiB
#include<cstdio> #include<algorithm> std::pair<int,int> a[300001]; int BIT[300001]; void upd(int x){while(x<=300000){BIT[x]++;x+=x&-x;}} int sum(int x){int r=0;while(x){r+=BIT[x];x-=x&-x;}return r;} int main() { long long r=0; int i,n; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i].first); a[i].second=i; } std::sort(a+1,a+n+1); for(i=1;i<=n;i++) { r+=std::min(a[i].second-sum(a[i].second)-1,n-a[i].second-i+sum(a[i].second)+1); upd(a[i].second); } printf("%lld",r); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...