Submission #1101

#TimeUsernameProblemLanguageResultExecution timeMemory
1101tncks0121공장 (KOI13_factory)C++98
9.40 / 20
249 ms10840 KiB
#include <stdio.h> int n; int val[1000007]; int seq[500007]; int bit[1048577], bin; void put(int key) { int ind = bin+key-1; while(ind) { bit[ind]++; ind /= 2; } } int sum(int left, int right) { int lind = bin+left-1; int rind = bin+right-1; int rval=0; while(lind <= rind) { if(lind%2 == 1) rval += bit[lind]; if(rind%2 == 0) rval += bit[rind]; lind = (lind+1)/2; rind = (rind-1)/2; }return rval; } int main(void) { int i, v; long long res=0; scanf("%d", &n); for(bin=1;bin<n;bin*=2); for(i = 1; i <= n; i++) scanf("%d", &seq[i]); for(i = 1; i <= n; i++) { scanf("%d", &v); val[v]= i; } for(i = 1; i <= n; i++) seq[i] = val[seq[i]]; for(i = 1; i <= n; i++) { res += sum(seq[i]+1, n); put(seq[i]); }printf("%d\n", res); 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...