Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

/**
 * n ????????´??°???????????°??? S ??¨???q ????????°????????´??°???????????°???
T ??????????????????T ?????????????????´??°????????§ S
?????????????????????????????° C
???????????????????????°????????????????????????????????????

??\\???
???????????? n??????????????? S ?????¨??? n ????????´??°???????????????
q??????????????? T ?????¨??? q ????????´??°????????????????????????

??????
C ???????????????????????????????????????

??¶?´?
S ???????´???????????????´??????????????????
n???100,000
q???50,000
0???S???????´????10^9
0???T???????´????10^9
T ???????´???????????????°??????
??\\?????? 1
5
1 2 3 4 5
3
3 4 1
????????? 1
3
??\\?????? 2
3
1 2 3
1
5
????????? 2
0
 */

#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>

bool binarySearch(const std::vector<unsigned int> &Source,
                  const unsigned int &Key) {
  unsigned int left = 0;
  unsigned int right = Source.size();
  unsigned int mid = 0;
  while (left < right) {
    mid = (left + right) / 2;
    if (Source[mid] == Key) {
      return true;
    } else if (Key < Source[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return false;
}

int main(int argc, char const *argv[]) {
  std::vector<unsigned int> S;
  std::vector<unsigned int> T;
  std::string Param;
  std::istringstream iss;
  unsigned int n = 0;
  unsigned int q = 0;
  getline(std::cin, Param);
  iss.str(Param);
  iss >> n;
  iss.clear();
  getline(std::cin, Param);
  iss.str(Param);
  unsigned int Si;
  for (size_t i = 0; i < n; i++) {
    iss >> Si;
    S.push_back(Si);
  }
  iss.clear();
  getline(std::cin, Param);
  iss.str(Param);
  iss >> q;
  iss.clear();
  getline(std::cin, Param);
  iss.str(Param);
  unsigned int Ti;
  for (size_t i = 0; i < q; i++) {
    iss >> Ti;
    T.push_back(Ti);
  }

  unsigned short C = 0;
  for (const auto &e : T) {
    bool Result = binarySearch(S, e);
    if (Result) {
      C++;
    }
  }

  std::cout << C << std::endl;
  return 0;
}

Error: TLE

Fixed submission:

/**
 * n ????????´??°???????????°??? S ??¨???q ????????°????????´??°???????????°???
T ??????????????????T ?????????????????´??°????????§ S
?????????????????????????????° C
???????????????????????°????????????????????????????????????

??\\???
???????????? n??????????????? S ?????¨??? n ????????´??°???????????????
q??????????????? T ?????¨??? q ????????´??°????????????????????????

??????
C ???????????????????????????????????????

??¶?´?
S ???????´???????????????´??????????????????
n???100,000
q???50,000
0???S???????´????10^9
0???T???????´????10^9
T ???????´???????????????°??????
??\\?????? 1
5
1 2 3 4 5
3
3 4 1
????????? 1
3
??\\?????? 2
3
1 2 3
1
5
????????? 2
0
 */

#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>

bool binarySearch(std::vector<unsigned int> Source, unsigned int Key) {
  unsigned int left = 0;
  unsigned int right = Source.size();
  while (left < right) {
    unsigned short mid = (left + right) / 2;
    if (Source[mid] == Key) {
      return true;
    } else if (Key < Source[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return false;
}

int main(int argc, char const *argv[]) {
  std::vector<unsigned int> S;
  std::vector<unsigned int> T;
  std::string Param;
  std::istringstream iss;
  unsigned int n = 0;
  unsigned int q = 0;
  getline(std::cin, Param);
  iss.str(Param);
  iss >> n;
  iss.clear();
  getline(std::cin, Param);
  iss.str(Param);
  unsigned int Si;
  for (size_t i = 0; i < n; i++) {
    iss >> Si;
    S.push_back(Si);
  }
  iss.clear();
  getline(std::cin, Param);
  iss.str(Param);
  iss >> q;
  iss.clear();
  getline(std::cin, Param);
  iss.str(Param);
  unsigned int Ti;
  for (size_t i = 0; i < q; i++) {
    iss >> Ti;
    T.push_back(Ti);
  }

  unsigned short C = 0;
  for (const auto &e : T) {
    bool Result = binarySearch(S, e);
    if (Result) {
      C++;
    }
  }

  std::cout << C << std::endl;
  return 0;
}