title: Need help to understand difference between two usages of unordered_map
body: <p>I was solving a question where i wrote two pieces of code as follows.
  Note: 'mp' is an already filled unordered_map&lt;int,int&gt;.</p>
  <p>1.</p>
  <pre><code>for(int i=0;i&lt;n;i++)
  for(int j=0;j&lt;n;j++)
  {
   ans+=mp[A[i]+B[j]]; // did this because, if A[i]+B[j] doesn't exist, mp[A[i]+B[j]]=0.
  }
  </code></pre>
  <ol start="2">
  <li></li>
  </ol>
  <pre><code>for(int i=0;i&lt;n;i++)
      for(int j=0;j&lt;n;j++)
      {
      auto it=mp.find(A[i]+B[j]);
      if(it!=mp.end())
          ans+=it-&gt;second;
      }
  </code></pre>
  <p>Now sol2 gave me a speedup of around 140 ms than sol1 and this is not due to different runtimes at submissions at different times. This increment stays constant and I can't understand, why it happened? Both codes do the same operation of adding mapped value of A[i]+B[j] (if it exists) to 'ans'.</p>