Submission #14190

#TimeUsernameProblemLanguageResultExecution timeMemory
14190paulsohn공장 (KOI13_factory)C++98
20 / 20
263 ms9084 KiB
#include<cstdio> #include<queue> #include<algorithm> using namespace std; int N,D[1000001],FT[1048576]; long long S; void add(int o, int d){ if(o<1) return; FT[o]+=d; add(o>>1,d); } int calc(int L, int R){ //[L,R] int crumb=0,l=L>>1,r=R>>1; if(L>R) return 0; if(L==R) return FT[L]; if(L&1){ crumb+=FT[L]; l=(L+1)>>1; } if(R&1==0){ crumb+=FT[R]; r=(R-1)>>1; } return crumb+calc(l,r); } int main(){ int i,j,n; scanf("%d",&N); for(i=0;i<N;++i){ scanf("%d",&n); D[n]=i; } for(i=0;i<N;++i){ scanf("%d",&n); S+=calc(524288+D[n],524288+N); add(524288+D[n],1); } printf("%lld",S); 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...