Submission #5376

#TimeUsernameProblemLanguageResultExecution timeMemory
5376baneling100공장 (KOI13_factory)C++98
9.40 / 20
216 ms9412 KiB
#include <stdio.h> #include <algorithm> using namespace std; pair <int,int> a[500001]; int n, check[1000001], idx[131073], nn; long long ans; void input(void) { int i, temp; scanf("%d",&n); for(i=1 ; i<=n ; i++) { scanf("%d",&temp); check[temp]=i; } for(i=1 ; i<=n ; i++) { scanf("%d",&temp); a[i]=make_pair(check[temp],i); } sort(a+1,a+n+1); for(nn=1 ; nn<n ; nn*=2); } void process(void) { int i, temp, hab; for(i=n ; i>=1 ; i--) { temp=a[i].second-1; hab=0; while(temp>0) { hab+=idx[temp]; temp&=~(~temp+1); } ans+=hab; temp=a[i].second; while(temp<=nn) { idx[temp]++; temp+=temp&(~temp+1); } } } void output(void) { printf("%lld",ans); } int main(void) { input(); process(); output(); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...