mac_n_cheese_pog's blog

By mac_n_cheese_pog, history, 3 years ago, In English

after thinking for 2 hours i cant solve this problem https://mirror.codeforces.com/edu/course/2/lesson/9/1/practice/contest/307092/problem/C can someone help me?

  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
Rev. 5   Vote: I like it +3 Vote: I do not like it

Create a count map for array $$$b$$$, say $$$cnt$$$. Then iterate over $$$a$$$ and for each $$$a_i$$$, $$$ans$$$ is increased by $$$cnt[a_i]$$$. cmiiw!

for(int i = 1; i <= b.size(); i++){
cnt[b[i]]++;
}

for(int i = 1; i <= a.size(); i++){
ans += cnt[a[i]];
}