alexjercan/bugnet huggingface dataset:
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <istream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
//------------------------------------define------------------------//

//------------------------------------typedef-----------------------//

using namespace std;

int n, A[1000000];
//--------------------------------------------------------------//
int binafySearch(int key) {
  int left = 0;
  int right = n;
  int midle;
  while (left < right) {
    midle = (left + right) / 2;
    if (key == A[midle]) {
      return 1;
    }
    if (key < A[midle]) {
      right = midle;
    } else if (key > A[midle]) {
      left = midle + 1;
    }
  }
  return 0;
}

int main() {
  int sum = 0;
  int q;
  int key;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> key;

    if (binafySearch(key)) {
      sum++;
    }
  }
  printf("%d\\n", sum);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <istream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
//------------------------------------define------------------------//
#define PB push_buck
#define MP make_pair
//------------------------------------typedef-----------------------//
typedef long long LL;

using namespace std;

int a, b, c, d, e, f, g, h, i, j, k, l, n;
vector<int> s1;
vector<pair<int, int>> s2;
stack<int> s3;
queue<int> s4;
list<int> s5;

//--------------------------------------------------------------//
int binafySearch(int key) {
  int left = 0;
  int right = n;
  int midle;
  int A[1000000];
  while (left < right) {
    midle = (left + right) / 2;
    if (key == A[midle]) {
      return 1;
    } else if (key < A[midle]) {
      right = midle;
    } else if (key > A[midle]) {
      left = midle;
    }
  }
}

int main() {
  int sum = 0;
  int A[1000000];
  int q;
  int key;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> key;

    if (binafySearch(key)) {
      sum++;
    }
  }
  printf("%d", sum);
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#define SIZE 100000
#define SIZE2 50000
using namespace std;

bool compare(int a, int b) { return a < b; }

int a[SIZE];
int b[SIZE2];
int main() {
  int q;

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> a[i];
  }

  sort(a, a + q, compare);

  int t;
  cin >> t;
  for (int j = 0; j < t; j++) {
    cin >> b[j];
  }

  int n = 0;
  for (int i = 0; i < t; i++) {
    int l = 0, r = q - 1;
    while (l <= r) {
      int m = (l + r) / 2;
      if (a[m] < b[i])
        l = m + 1;
      else if (a[m] > b[i])
        r = m - 1;
      else if (a[m] == b[i]) {
        n++;
        break;
      }
    }
  }

  cout << n << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#define SIZE 10000
using namespace std;

bool compare(int a, int b) { return a < b; }

int main() {
  int q;
  int a[SIZE];

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> a[i];
  }

  sort(a, a + q, compare);

  int t;
  cin >> t;
  int b[SIZE];
  for (int j = 0; j < t; j++) {
    cin >> b[j];
  }

  int n = 0;
  for (int i = 0; i < t; i++) {
    int l = 0, r = q - 1;
    while (l <= r) {
      int m = (l + r) / 2;
      if (a[m] < b[i])
        l = m + 1;
      else if (a[m] > b[i])
        r = m - 1;
      else if (a[m] == b[i]) {
        n++;
        break;
      }
    }
  }

  cout << n << endl;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int main(int argc, char const *argv[]) {
  int n, q, target;
  int findCount = 0; // ???????????£?????°????????°
  int inputSequence[100000];

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &inputSequence[i]);
  }

  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &target);
    int begin = 0, end = n - 1;
    do {
      int current = (begin + end) / 2;
      if (inputSequence[current] == target) {
        findCount++;
        break;
      }
      // ?????????????????§????????????????????????
      else if (inputSequence[current] < target) {
        begin = current + 1;
      }
      // ????????????????°?????????????????????????
      else if (inputSequence[current] > target) {
        end = current - 1;
      }
    } while (begin <= end); // ????????¨????°??????\\???????????£????????????
  }

  printf("%d\\n", findCount);
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>

int main(int argc, char const *argv[]) {
  int n, q, target;
  int findCount = 0; // ???????????£?????°????????°
  int inputSequence[10000];

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &inputSequence[i]);
  }

  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &target);
    int begin = 0, end = n - 1;
    do {
      int current = (begin + end) / 2;
      if (inputSequence[current] == target) {
        findCount++;
        break;
      }
      // ?????????????????§????????????????????????
      else if (inputSequence[current] < target) {
        begin = current + 1;
      }
      // ????????????????°?????????????????????????
      else if (inputSequence[current] > target) {
        end = current - 1;
      }
    } while (begin <= end); // ????????¨????°??????\\???????????£????????????
  }

  printf("%d\\n", findCount);
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> s(n);
  FOR(i, 0, n) { cin >> s[i]; }

  int q;
  cin >> q;
  vector<int> t(q);
  int cnt = 0;
  FOR(i, 0, q) {
    cin >> t[i];
    if (*lower_bound(s.begin(), s.end(), t[i]) == t[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> s(n);
  FOR(i, 0, n) { cin >> s[i]; }

  int q;
  cin >> q;
  vector<int> t(q);
  int cnt = 0;
  FOR(i, 0, q) {
    cin >> t[i];
    int left = 0, right = n - 1;
    int mid;
    while (left < right) {
      mid = (left + right) / 2;
      if (t[i] == s[mid]) {
        cnt++;
        break;
      }
      if (t[i] > s[mid]) {
        left = mid;
        ;
      }
      if (t[i] < s[mid]) {
        right = mid;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {

  int n, a[100000], m, b, result = 0, i, j;

  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> b;
    for (j = 0; j < n; j++)
      if (b == a[j]) {
        result++;
        break;
      }
  }

  cout << result << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {

  int n, a[10000], m, b, result = 0, i, j;

  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> b;
    for (j = 0; j < n; j++)
      if (b == a[j]) {
        result++;
        break;
      }
  }

  cout << result << endl;

  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define r(i, n) for (int i = 0; i < n; i++)

using namespace std;

// input
vector<int> S, T;

int main() {
  // input, S is ascending
  int n, q;
  cin >> n;
  while (n--) {
    int a;
    cin >> a;
    S.push_back(a);
  }
  cin >> q;
  while (q--) {
    int a;
    cin >> a;
    T.push_back(a);
  }

  // binary search
  int C = 0;
  r(i, T.size()) {
    if (binary_search(S.begin(), S.end(), T[i]))
      C++;
  }

  cout << C << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

#define r(i, n) for (int i = 0; i < n; i++)

using namespace std;

// input
vector<int> S, T;

int main() {
  // input
  int n, q;
  cin >> n;
  while (n--) {
    int a;
    cin >> a;
    S.push_back(a);
  }
  cin >> q;
  while (q--) {
    int a;
    cin >> a;
    T.push_back(a);
  }

  // linear search
  int C = 0;
  r(i, T.size()) {
    r(j, S.size()) {
      if (T[i] == S[j]) {
        C++;
        break;
      }
    }
  }

  cout << C << endl;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

#define N 100000

int S[N], T[N];
int n, m;

int binary() {
  int l, r, mid, i;
  int count = 0;
  for (i = 0; i < m; i++) {
    l = 0;
    r = n;
    while (l < r) {
      mid = (l + r) / 2;
      if (S[mid] == T[i]) {
        count++;
        l = r;
      } else if (T[i] < S[mid]) {
        r = mid;
      } else {
        l = mid + 1;
      }
    }
  }
  return count;
}

int main() {
  scanf("%d\\n", &n);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  scanf("%d\\n", &m);
  for (i = 0; i < m; i++) {
    scanf("%d", &T[i]);
  }

  int c = binary();

  printf("%d\\n", c);
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

#define N 10000

int S[N], T[N];
int n, m;

int binary() {
  int l, r, mid, i;
  int count = 0;
  for (i = 0; i < m; i++) {
    l = 0;
    r = n;
    while (l < r) {
      mid = (l + r) / 2;
      if (S[mid] == T[i]) {
        count++;
        l = r;
      } else if (T[i] < S[mid]) {
        r = mid;
      } else {
        l = mid + 1;
      }
    }
  }
  return count;
}

int main() {
  scanf("%d\\n", &n);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  scanf("%d\\n", &m);
  for (i = 0; i < m; i++) {
    scanf("%d", &T[i]);
  }

  int c = binary();

  printf("%d\\n", c);
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, q, ans;
  ans = 0;
  cin >> n;
  int s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  cin >> q;
  int t[q];
  for (int i = 0; i < q; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < q; i++) {
    int left = 0;
    int right = n;
    int mid;
    while (left < right) {
      mid = (left + right) / 2;
      if (s[mid] == t[i]) {
        ans++;
        goto l;
      } else if (t[i] < s[mid])
        right = mid;
      else if (s[mid] < t[i])
        left = mid + 1;
    }
  l:;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, q, ans;
  ans = 0;
  cin >> n;
  int s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  cin >> q;
  int t[q];
  for (int i = 0; i < q; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < q; i++) {
    int left = 0;
    int right = n;
    int mid;
    while (left < right) {
      mid = (left + right) / 2;
      if (s[mid] == t[i]) {
        ans++;
        break;
      } else if (t[i] < s[mid])
        right = mid;
      else if (s[mid] < t[i])
        left = mid;
    }
  }
  cout << ans << endl;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int S[100000], T[100000], n, q, key, low = 0, upper = 0, mid, flag;
  int i = 0, cnt = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }

  for (i = 0; i < q; i++) {
    ///------------------------------
    key = T[i];
    low = 0;
    upper = 0;
    mid = 0;
    upper = n; // n-1

    mid = (low + upper) / 2;
    while (low < upper) {
      // mid=(low+upper)/2;

      if (S[mid] == key) {

        flag = 1;
        cnt++;
        break;
      }

      if (S[mid] < key) {
        low = mid + 1;
      } else {
        upper = mid; // mid-1
      }
      mid = (low + upper) / 2; //
    }
    if (flag != 1) {
      // no
    }

    ///------------------------------
  }

  cout << cnt << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int S[100000], T[100000], n, q, key, low = 0, upper = 0, mid, flag;
  int i = 0, cnt = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }

  for (i = 0; i < q; i++) {
    ///------------------------------
    key = T[i];
    low = 0;
    upper = 0;
    mid = 0;
    upper = n; // n-1

    mid = (low + upper) / 2;
    while (low <= upper) {
      // mid=(low+upper)/2;

      if (S[mid] == key) {

        flag = 1;
        cnt++;
        break;
      }

      if (S[mid] < key) {
        low = mid + 1;
      } else {
        upper = mid; // mid-1
      }
      mid = (low + upper) / 2; //
    }
    if (flag != 1) {
      // no
    }

    ///------------------------------
  }

  cout << cnt << endl;

  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main(int argc, char const *argv[]) {
  int n, val, tmp;
  int len = 0;
  std::cin >> n;
  std::vector<int> S;
  S.reserve(100000);

  for (size_t i = 0; i < n; i++) {
    std::cin >> val;
    if (i == 0 || val != tmp) {
      len++;
      S[len] = val;
      tmp = val;
    }
  }

  int num = 0;

  int q;
  std::cin >> q;
  for (size_t i = 0; i < q; i++) {
    std::cin >> val;
    int lower = 0;
    int upper = len;
    int mid = upper / 2;
    while (1) {
      if (val == S[mid] || val == S[mid + 1] || val == S[mid - 1]) {
        num++;
        break;
      }
      if (S[0] <= val && val <= S[mid - 1]) {
        upper = mid;
        mid = (mid + lower) / 2;
      } else if (S[mid + 1] <= val && val <= S[upper]) {
        lower = mid;
        mid = (mid + upper) / 2;
      } else {
        break;
      }
    }
  }
  std::cout << num << '\\n';

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  std::cin >> n;
  std::vector<int> S;
  S.reserve(100000);
  for (size_t i = 0; i < n; i++) {
    std::cin >> S[i];
  }

  int mid;
  if (n % 2 == 0) {
    mid = n / 2;
  } else {
    mid = (n - 1) / 2;
  }

  int num = 0;

  int q;
  std::cin >> q;
  int val;
  for (size_t i = 0; i < q; i++) {
    std::cin >> val;
    while (1) {
      if (val == S[mid]) {
        num++;
        break;
      }
      if (S[0] <= val && val <= S[mid - 1]) {
        mid = mid / 2;
      } else if (S[mid + 1] <= val && val <= S[n - 1]) {
        mid = (mid + n) / 2;
      } else {
        break;
      }
    }
  }
  std::cout << num << '\\n';

  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  std::cin >> n;

  std::vector<int> S;
  S.resize(n, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> S[i];
  }

  int q;
  std::cin >> q;

  std::vector<int> T;
  T.resize(q, 0);
  for (int i = 0; i < q; i++) {
    std::cin >> T[i];
  }

  int cnt = 0;
  for (int i = 0; i < q; i++) {
    if (std::binary_search(S.begin(), S.end(), T[i]))
      cnt++;
  }

  std::cout << cnt << std::endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

bool binary_search(std::vector<int>::iterator a, std::vector<int>::iterator b,
                   int key) {

  std::vector<int>::iterator x = a + (std::distance(a, b) / 2);
  if (*x == key)
    return true;
  if (std::distance(a, b) == 0)
    return false;
  if (*x < key)
    return binary_search(x + 1, b, key);
  if (*x > key)
    return binary_search(a, x - 1, key);
}

int main() {
  int n;
  std::cin >> n;

  std::vector<int> S;
  S.resize(n, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> S[i];
  }

  int q;
  std::cin >> q;

  std::vector<int> T;
  T.resize(q, 0);
  for (int i = 0; i < q; i++) {
    std::cin >> T[i];
  }

  int cnt = 0;
  for (int i = 0; i < q; i++) {
    if (binary_search(S.begin(), S.end(), T[i]))
      cnt++;
  }

  std::cout << cnt << std::endl;

  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

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

bool binary_search(std::vector<int>::iterator a, std::vector<int>::iterator b,
                   int key) {
  if (std::distance(a, b) == 0)
    return false;
  std::vector<int>::iterator mid = a + std::distance(a, b) / 2;
  if (*mid == key)
    return true;
  if (*mid < key)
    return binary_search(mid + 1, b, key);
  else
    return binary_search(a, mid, key);
}

int main() {
  int n;
  std::cin >> n;

  std::vector<int> S;
  S.resize(n, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> S[i];
  }

  int q;
  std::cin >> q;

  std::vector<int> T;
  T.resize(q, 0);
  for (int i = 0; i < q; i++) {
    std::cin >> T[i];
  }

  int cnt = 0;
  for (int i = 0; i < q; i++) {
    if (binary_search(S.begin(), S.end(), T[i]))
      cnt++;
  }

  std::cout << cnt << std::endl;

  return 0;
}

Error: 0

Fixed submission:

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

bool binary_search(std::vector<int>::iterator a, std::vector<int>::iterator b,
                   int key) {
  if (std::distance(a, b) == 0)
    return false;
  std::vector<int>::iterator mid = a + std::distance(a, b) / 2;
  if (*mid == key)
    return true;
  if (*mid < key)
    return binary_search(mid, b, key);
  else
    return binary_search(a, mid - 1, key);
}

int main() {
  int n;
  std::cin >> n;

  std::vector<int> S;
  S.resize(n, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> S[i];
  }

  int q;
  std::cin >> q;

  std::vector<int> T;
  T.resize(q, 0);
  for (int i = 0; i < q; i++) {
    std::cin >> T[i];
  }

  int cnt = 0;
  for (int i = 0; i < q; i++) {
    if (binary_search(S.begin(), S.end(), T[i]))
      cnt++;
  }

  std::cout << cnt << std::endl;

  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int n, S[1000000];

int binarySearch(int val) {
  int left = 0, right = n;
  while (left < right) {
    int mid = (left + right) / 2;
    if (S[mid] == val) {
      // cout << val;
      return mid;
    } else if (val < S[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return -1;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  int q, val, sum = 0;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> val;
    if (binarySearch(val) >= 0) {
      sum++;
    }
  }

  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

bool lsearch(int A[], int n, int val) {
  for (int i = 0; i < n; i++) {
    if (A[i] == val)
      return true;
  }
  return false;
}

int main() {
  int n, A[10001];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  int q, val, sum = 0;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> val;
    if (lsearch(A, n, val))
      sum++;
  }

  cout << sum << endl;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, n) for (int i = (a); i > n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
inline int f(int n, vi s, int q, vi t) {
  int cnt = 0;
  rep(j, 0, q) {
    if (find(all(s), t[j]) != s.end())
      ++cnt;
  }
  return cnt;
}
int main() {
  int n;
  cin >> n;
  unordered_set<int> ss;
  {
    ll t;
    rep(i, 0, n) {
      cin >> t;
      ss.emplace(t);
    }
  }
  vi s(all(ss));
  int q;
  cin >> q;
  vi t(q);
  rep(i, 0, q) cin >> t[i];
  P(f(len(s), s, q, t));
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, n) for (int i = (a); i > n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
inline int f(int n, vi s, int q, vi t) {
  int cnt = 0;
  rep(j, 0, q) {
    if (count(all(s), t[j]))
      ++cnt;
  }
  return cnt;
}
int main() {
  int n;
  cin >> n;
  unordered_set<int> ss;
  {
    ll t;
    rep(i, 0, n) {
      cin >> t;
      ss.emplace(t);
    }
  }
  vi s(all(ss));
  int q;
  cin >> q;
  vi t(q);
  rep(i, 0, q) cin >> t[i];
  P(f(len(s), s, q, t));
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=jp*/

#include <iostream>
#include <vector>

using namespace std;

vector<int> s;

int mybinarysearch(int value, int max, int min) {
  int mid = (max + min) / 2;

  if (max <= min) {
    return 0;
  } else if (s[mid] == value) {
    return 1;
  } else if (s[mid] < value) {
    return mybinarysearch(value, max, mid + 1);
  } else {
    return mybinarysearch(value, mid, min);
  }
}

int main() {
  int count = 0;
  int n, q;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    s.push_back(tmp);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int tmp;
    cin >> tmp;
    count += mybinarysearch(tmp, s.size(), 0);
  }
  cout << count << endl;
  return 0;
}

Error: TLE

Fixed submission:

/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=jp*/

#include <iostream>
#include <vector>

using namespace std;

int mybinarysearch(vector<int> s, int value, int max, int min) {
  int mid = (max + min) / 2;

  if (max <= min) {
    return 0;
  } else if (s[mid] == value) {
    return 1;
  } else if (s[mid] < value) {
    return mybinarysearch(s, value, max, mid + 1);
  } else {
    return mybinarysearch(s, value, mid, min);
  }
}

int main() {
  int count = 0;
  int n, q;
  vector<int> s;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    s.push_back(tmp);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int tmp;
    cin >> tmp;
    count += mybinarysearch(s, tmp, s.size(), 0);
  }
  cout << count << endl;
  return 0;
}