Submission #1394

#TimeUsernameProblemLanguageResultExecution timeMemory
1394gijun0102공장 (KOI13_factory)C++98
20 / 20
356 ms12608 KiB
#include <cstdio> int tree[2000000],base,index[1001000]; int sum(int l,int r){ int tmp=0; while(l<r){ if(l%2==1) tmp+=tree[l++]; if(r%2==0) tmp+=tree[r--]; l>>=1,r>>=1; } if(l==r) tmp+=tree[l]; return tmp; } void add(int index){ while(index){ tree[index]++; index>>=1; } } int main(){ int n,i,tmp; long long ans=0; scanf("%d",&n); for(base=1;base<n;base*=2); for(i=1;i<=n;i++){ scanf("%d",&tmp); index[tmp]=i; } for(i=0;i<n;i++){ scanf("%d",&tmp); tmp=index[tmp]; ans+=sum(tmp+1+base,n+base); add(tmp+base); } printf("%lld",ans); }
#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...