Skip to content

Instantly share code, notes, and snippets.

@KhaledElshamy
Created January 19, 2017 15:45
Show Gist options
  • Select an option

  • Save KhaledElshamy/5481ebcda63a5312a85cc5a692a2bd13 to your computer and use it in GitHub Desktop.

Select an option

Save KhaledElshamy/5481ebcda63a5312a85cc5a692a2bd13 to your computer and use it in GitHub Desktop.
B. Effective Approach-codeforces
// working.cpp by Bill Weinman <http://bw.org/>
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, index1[100001];
cin>>n;
for (int i = 1; i <= n; ++i)
{
cin>>a;
index1[a] = i;
}
int m, b;
cin>>m;
long long Vasya(0), Petya(0);
while (m--)
{
cin>>b;
Vasya += index1[b];
Petya += (n + 1 - index1[b]);
}
cout<< Vasya<<" "<<Petya<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment