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

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int main(void) {
  int n, q;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int ans = 0;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    vector<int>::iterator it = lower_bound(s.begin(), s.end(), t);
    if (it != s.end() && *it == t)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int main(void) {
  while (true) {
    int n, q;
    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    int ans = 0;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int t;
      cin >> t;
      vector<int>::iterator it = lower_bound(s.begin(), s.end(), t);
      if (it != s.end() && *it == t)
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

bool search(vector<int> &S, int s, int b, int e) {
  int m = (e + b) / 2;
  if (m < b)
    return false;
  int _s = S[m];
  if (s == _s)
    return true;
  if (b == e)
    return false;
  if (_s > s)
    return search(S, s, b, m - 1);
  if (_s < s)
    return search(S, s, m + 1, e);
}

int main() {
  int n;
  cin >> n;
  vector<int> S(n);
  for (auto &s : S)
    cin >> s;
  int q;
  cin >> q;
  int C = 0;
  while (q--) {
    int t;
    cin >> t;
    if (search(S, t, 0, n - 1))
      C++;
  }
  cout << C << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

bool search(vector<int> &S, int s, int b, int e) {
  int m = (e + b) / 2;
  int _s = S[m];
  if (s == _s)
    return true;
  if (b == e)
    return false;
  if (_s > s)
    return search(S, s, b, m - 1);
  if (_s < s)
    return search(S, s, m + 1, e);
}

int main() {
  int n;
  cin >> n;
  vector<int> S(n);
  for (auto &s : S)
    cin >> s;
  int q;
  cin >> q;
  int C = 0;
  while (q--) {
    int t;
    cin >> t;
    if (search(S, t, 0, n - 1))
      C++;
  }
  cout << C << endl;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

bool binary_search(vector<int> v, int kay) {
  int left = 0;
  int right = SZ(v);
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (v[mid] == kay)
      return true;
    else if (kay < v[mid])
      right = mid;
    else
      left = mid + 1;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  vector<int> v;
  int t;
  REP(_, n) {
    cin >> t;
    v.PB(t);
  }

  cin >> n;
  int count = 0;
  REP(_, n) {
    cin >> t;
    if (binary_search(v, t))
      count++;
  }

  cout << count << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

bool binary_search(vector<int> v, int kay) {
  int left = 0;
  int right = SZ(v);
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (v[mid] == kay)
      return true;
    else if (kay < v[mid])
      right = mid;
    else
      left = mid;
  }
  return false;
}

signed main() {
  // cin.tie(0);
  // ios::sync_with_stdio(false);

  int n;
  cin >> n;

  vector<int> v;
  int t;
  REP(_, n) {
    cin >> t;
    v.PB(t);
  }

  cin >> n;
  int count = 0;
  REP(_, n) {
    cin >> t;
    if (binary_search(v, t))
      count++;
  }

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

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

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

  int M;
  cin >> M;

  int Q[M];
  for (int i = 0; i < M; i++)
    cin >> Q[i];
  sort(Q, Q + M);

  int left = 0, right, m, count = 0;

  for (int i = 0; i < M; i++) {
    right = N - 1;
    m = (left + right) / 2;

    while (left <= right) {
      if (S[m] == Q[i]) {
        count++;
        left = m + 1;
        break;
      } else if (S[m] > Q[i]) {
        right = m - 1;
      } else { // S[m] < Q[i]
        left = m + 1;
      }
      m = (left + right) / 2;
    }
  }
  cout << count << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define CLR(a) memset((a), 0, sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};
const double EPS = 1e-10;
const double PI = acos(-1.0);

bool is_exist(vector<int> vec, int n, int head, int hip) {
  int mid = (head + hip) / 2;
  if (vec[mid] == n)
    return true;
  else if (head == hip)
    return false;

  if (vec[mid] < n)
    return is_exist(vec, n, mid, hip);
  if (vec[mid] > n)
    return is_exist(vec, n, head, mid);

  return false;
}

signed main() {
  // cin.tie(0);
  // ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> s;
  REP(_, n) {
    int num;
    cin >> num;
    s.PB(num);
  }

  int q;
  cin >> q;
  int res = 0;
  REP(_, q) {
    int num;
    cin >> num;

    if (is_exist(s, num, 0, s.size()))
      res++;
  }

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

#include <iostream>
#include <string>

using namespace std;

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

  int count = 0;

  for (int i = 0; i < q; i++) {
    int left = 0;
    int right = n;
    while (left < right) {
      int mid = (left + right) / 2;
      if (S[mid] == T[i]) {
        count++;
        break;
      } else if (T[i] < S[mid]) {
        right = mid;
      } else if (T[i] > S[mid]) {
        left = mid + 1;
      }
    }
  }
  std::cout << count << '\\n';
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

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

  int count = 0;

  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (S[j] == T[i]) {
        count++;
        break;
      }
    }
  }
  std::cout << count << '\\n';
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int A[1000000], n;

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

int main() {
  int i, q, key, sum = 0;

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

  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &key);
    if (binarySearch(key))
      sum++;
  }
  printf("%d\\n", sum);

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int A[1000000], n;

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

int main() {
  int i, q, key, sum = 0;

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

  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &key);
    if (binarySearch(key))
      sum++;
  }
  printf("%d\\n", sum);

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

#include <iostream>
using namespace std;
int main() {
  int n, s[100000], q, t[50000], i, j, l, r, m, count = 0;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> t[i];
  }

  // Binary Search

  for (i = 0; i < q; i++) {
    l = 0;
    r = n;
    while (l < r) {
      m = (l + r) / 2;
      if (s[m] > t[i]) {
        r = m;
      } else if (s[m] < t[i]) {
        l = m + 1;
      } else {
        count++;
        break;
      }
    }
  }

  cout << count << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, s[100000], q, t[50000], i, j, l, r, m, count = 0;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> t[i];
  }

  // Binary Search

  for (i = 0; i < q; i++) {
    l = 0;
    r = n;
    while (l < r) {
      m = (l + r) / 2;
      if (s[m] > t[i]) {
        r = m;
      } else if (s[m] < t[i]) {
        l = m;
      } else {
        count++;
        break;
      }
    }
  }

  cout << count << endl;

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

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string>

int binarysearch(int a[], int n, int key) {
  int left = 0;
  int right = n;
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == a[mid])
      return 1;
    if (key > a[mid])
      left = mid + 1;
    else if (key < a[mid])
      right = mid;
  }
  return 0;
}
using namespace std;
int main() {
  int i, n, a[100001], q, key, sum = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    if (binarysearch(a, n, key))
      sum++;
  }
  printf("%d\\n", sum);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string>

int binarysearch(int a[], int n, int key) {
  int left = 0;
  int right = n;
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == a[mid])
      return 1;
    if (key > a[mid])
      left = mid + 1;
    else if (key < a[mid])
      right = mid;
  }
  return 0;
}
using namespace std;
int main() {
  int i, n, a[10001], q, key, sum = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    if (binarysearch(a, n, key))
      sum++;
  }
  printf("%d\\n", sum);
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int A[1000000], n;

int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;

  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid])
      return 1;
    if (key > A[mid])
      left = mid + 1;
    else if (key < A[mid])
      right = mid;
  }
  return 0;
}

int main() {
  int i, q, k, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> k;
    if (binarySearch(k))
      sum++;
  }
  cout << sum << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while (A[i] != key)
    i++;
  return i != n;
}

int main() {
  int i, n, A[10000 + 1], q, key, sum = 0;

  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &A[i]);

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    if (search(A, n, key))
      sum++;
  }
  printf("%d\\n", sum);

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

#include <stdio.h>

int A[1000000], n;

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

// 計算量はO(qn)
int main() {
  int i, q, key, sum = 0;

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

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    if (binarySearch(key))
      sum++;
  }

  printf("%d\\n", sum);

  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>

// Cにbooleanはないのでint(0 / 1)で判定する
int search(int A[], int n, int key) {
  int i = 0;
  A[n] = key; // 配列の末尾に番兵を用意
  while (A[i] != key)
    i++;
  return i != n; // i == n
                 // は番兵まで到達してしまった（存在しなかった）という意味になる
}

// 計算量はO(qn)
int main() {
  int i, n, A[10000 + 1], q, key, sum = 0;

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

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    if (search(A, n, key))
      sum++;
  }

  printf("%d\\n", sum);

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef pair<int, int> lake;

int main(void) {
  int n, q;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];
  cin >> q;
  vector<int> t(q);
  for (int i = 0; i < q; i++)
    cin >> t[i];
  // sort(s.begin(), s.end());
  // sort(t.begin(), t.end());
  int count = 0;
  for (int i = 0; i < q; i++) {
    int left = 0;
    int right = n;
    while (left < right) {
      int mid = (left + right) / 2;
      if (s[mid] == t[i]) {
        count++;
        break;
      } else if (s[mid] < t[i]) {
        left = mid + 1;
      } else {
        right = mid;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef pair<int, int> lake;

int main(void) {
  int n, q;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];
  cin >> q;
  vector<int> t(q);
  for (int i = 0; i < q; i++)
    cin >> t[i];
  // sort(s.begin(), s.end());
  // sort(t.begin(), t.end());
  int count = 0;
  for (int i = 0; i < q; i++) {
    int left = 0;
    int right = n;
    while (left < right) {
      int mid = (left + right) / 2;
      if (s[mid] == t[i]) {
        count++;
        break;
      } else if (s[mid] < t[i]) {
        left = mid;
      } else {
        right = mid;
      }
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;

bool search(int a[], int n, int t) {
  int left = 0, right = n;

  while (left < right) {
    int mid = (left + right) / 2;
    if (a[mid] == t) {
      return true;
    } else if (a[mid] < t) {
      left = mid + 1;
    } else {
      right = mid;
    }
  }
  return false;
}

int main() {
  int n1;
  cin >> n1;

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

  int n2;
  cin >> n2;

  int t, ans = 0;
  for (int i = 0; i < n2; i++) {
    scanf("%d", &t);
    if (search(s, n1, t))
      ans++;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;

bool search(int a[], int n, int t) {
  int left = 0, right = n;

  int mid = (left + right) / 2;
  while (left < right) {
    if (a[mid] = t) {
      return true;
    } else if (a[mid] < t) {
      left = mid + 1;
    } else {
      right = mid;
    }
  }
  return false;
}

int main() {
  int n1;
  cin >> n1;

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

  int n2;
  cin >> n2;

  int t, ans = 0;
  for (int i = 0; i < n2; i++) {
    scanf("%d", &t);
    if (search(s, n1, t))
      ans++;
  }

  cout << ans << endl;

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

#include <cstdio>
#include <iostream>
#define N 100000
#include <algorithm>
using namespace std;

int T[N + 1];
int BinarySearch(int k, int n) {
  int mid, left = 0, right = n;
  while (left < right) {
    mid = (left + right) / 2;
    if (T[mid] == k)
      return 1;
    else if (T[mid] < k)
      left = mid + 1;
    else if (T[mid] > k)
      right = mid;
  }
  return 0;
}
int main() {
  int n, q, t, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &T[i]);
  }
  sort(T, T + n);
  cin >> q;
  for (int i = 0; i < q; i++) {
    scanf("%d", &t);
    if (BinarySearch(t, n))
      sum++;
  }
  cout << sum << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#define N 100000
#include <algorithm>
using namespace std;

int T[N + 1];
int BinarySearch(int k, int n) {
  int left = 0, right = n;
  while (left < right) {
    int mid = (left + right) / 2;
    if (T[mid] == k)
      return 1;
    else if (T[mid] < k)
      left = mid;
    else if (T[mid] > k)
      right = mid;
  }
  return 0;
}
int main() {
  int n, q, t, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &T[i]);
  }
  sort(T, T + n);
  cin >> q;
  for (int i = 0; i < q; i++) {
    scanf("%d", &t);
    if (BinarySearch(t, n))
      sum++;
  }
  cout << sum << endl;
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m, cnt = 0;
  int st, en, syo;
  int tmp, a;
  int hi[100000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> hi[i];
    /*
                    for(int j=0;j<i;j++)
                    {
                            if(hi[j]>hi[i])
                            {
                                    tmp=hi[i];
                                    hi[i]=hi[j];
                                    hi[j]=tmp;
                            }
                    }
    */
  }
  sort(hi, hi + n);
  cin >> m;
  for (int i = 0; i < m; i++) {
    st = 0;
    en = n;
    cin >> a;
    while (st != en && st < en) {
      syo = st + ((en - st) / 2);
      if (a == hi[syo]) {
        cnt++;
        break;
      } else {
        if (hi[syo] > a)
          en = syo - 1;
        else
          st = syo + 1;
      }
    }
    if (st == en) {
      if (hi[st] == a)
        cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m, cnt = 0;
  int st, en, syo;
  int tmp, a;
  int hi[100000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> hi[i];
    for (int j = 0; j < i; j++) {
      if (hi[j] > hi[i]) {
        tmp = hi[i];
        hi[i] = hi[j];
        hi[j] = tmp;
      }
    }
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    st = 0;
    en = n;
    cin >> a;
    while (st != en && st < en) {
      syo = st + ((en - st) / 2);
      if (a == hi[syo]) {
        cnt++;
        break;
      } else {
        if (hi[syo] > a)
          en = syo - 1;
        else
          st = syo + 1;
      }
    }
    if (st == en) {
      if (hi[st] == a)
        cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int n;
bool my_search(int key, vector<int> v) {
  int up = n;
  int down = 0;
  while (down < up) {
    int mid = (up + down) / 2;
    if (v[mid] > key) {
      up = mid;
    } else if (v[mid] == key) {
      return true;
    } else {
      down = mid + 1;
    }
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());

  int q;
  cin >> q;
  int t;
  int cnt = 0;
  for (int i = 0; i < q; i++) {
    cin >> t;
    if (my_search(t, v)) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: 0
1
2
3


Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int n;
bool my_search(int key, vector<int> v) {
  int up = n;
  int down = 0;
  while (down < up) {
    int mid = (up + down) / 2;
    if (v[mid] > key) {
      up = mid;
    } else if (v[mid] == key) {
      return 1;
    } else {
      down = mid + 1;
    }
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());

  int q;
  cin >> q;
  int t;
  int cnt = 0;
  for (int i = 0; i < q; i++) {
    cin >> t;
    if (my_search(t, v)) {
      cnt++;
    }
    cerr << cnt << endl;
  }
  cout << cnt << endl;
  return 0;
}