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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
typedef long long ll;
typedef pair<int, int> pt;
const int INF = 1 << 29;
const double EPS = 1e-10;

vector<int> plane[10000];

int main() {
  int AN, BN, R, x, y, res;
  while (cin >> AN >> BN >> R && (AN || BN || R)) {
    res = 0;
    rep(i, 10000) plane[i].clear();
    rep(i, AN) {
      cin >> x >> y;
      plane[x].push_back(y);
    }
    rep(i, 10000) sort(plane[i].begin(), plane[i].end());

    rep(j, BN) {
      cin >> x >> y;
      for (int i = max(0, x - 4 * R); i < min(x + 4 * R + 1, 10000); i++) {
        int dx = abs(x - i);
        int dy = (int)sqrt((4 * R * 4 * R) - dx * dx);
        res += upper_bound(plane[i].begin(), plane[i].end(), y + dy) -
               lower_bound(plane[i].begin(), plane[i].end(), y - dy);
      }
    }
    cout << res << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
typedef long long ll;
typedef pair<int, int> pt;
const int INF = 1 << 29;
const double EPS = 1e-10;

vector<int> plane[10000];

int main() {
  int AN, BN, R, x, y, res;
  while (cin >> AN >> BN >> R && (AN || BN || R)) {
    res = 0;
    rep(i, AN) {
      cin >> x >> y;
      plane[x].push_back(y);
    }
    rep(i, 10000) sort(plane[i].begin(), plane[i].end());

    rep(j, BN) {
      cin >> x >> y;
      for (int i = max(0, x - 4 * R); i < min(x + 4 * R + 1, 10000); i++) {
        int dx = abs(x - i);
        int dy = (int)sqrt((4 * R * 4 * R) - dx * dx);
        res += upper_bound(plane[i].begin(), plane[i].end(), y + dy) -
               lower_bound(plane[i].begin(), plane[i].end(), y - dy);
      }
    }
    cout << res << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int an, bn, r, ans = 0, d, b0, b1, insides[41] = {0};
  vector<vector<int>> a(10000);
  scanf("%d %d %d", &an, &bn, &r);
  while (an || bn) {
    d = r * r << 4;
    for (int i = 0; i <= r << 2; i++) {
      for (int j = 0; j <= r << 2; j++) {
        if (i * i + j * j <= d) {
          insides[i]++;
        }
      }
    }
    for (int i = 0; i < an; i++) {
      int tmp1, tmp2;
      scanf("%d %d", &tmp1, &tmp2);
      a[tmp1].push_back(tmp2);
    }
    for (int i = 0; i < 10000; i++) {
      sort(a[i].begin(), a[i].end());
    }
    for (int i = 0; i < bn; i++) {
      scanf("%d %d", &b0, &b1);
      for (int c0 = max(-(r << 2) - 1, -b0); c0 < min((r << 2) + 1, 10000 - b0);
           c0++) {
        for (int c1 = 0; c1 < a[b0 + c0].size(); c1++) {
          if (abs(a[b0 + c0][c1] - b1) < insides[abs(c0)]) {
            ans++;
          }
        }
      }
    }
    printf("%d\\n", ans);
    ans = 0;
    for (int i = 0; i < 10000; i++) {
      a[i].clear();
    }
    for (int i = 0; i < 41; i++) {
      insides[i] = 0;
    }
    scanf("%d %d %d", &an, &bn, &r);
  }
  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <vector>
#define or0(a) (a) < 0 ? 0 : (a)
using namespace std;

int main() {
  int an, bn, r, ans = 0, d, b0, b1;
  vector<vector<int>> a(10000);
  scanf("%d %d %d", &an, &bn, &r);
  for (int i = 0; i < 10000; i++) {
    a[i].resize(313);
  }
  while (an) {
    d = 16 * r * r;
    for (int i = 0; i < an; i++) {
      int tmp1, tmp2;
      scanf("%d %d", &tmp1, &tmp2);
      a[tmp1][tmp2 >> 5] |= 1 << (tmp2 - ((tmp2 >> 5) << 5));
    }
    for (int i = 0; i < bn; i++) {
      scanf("%d %d", &b0, &b1);
      for (int idxx = or0(b0 - (r << 2)); idxx <= b0 + (r << 2) && idxx < 10000;
           idxx++) {
        for (int idxy = or0(b1 - (r << 2)) >> 5;
             idxy <= b1 + ((r << 2) >> 5) && idxy < 313; idxy++) {
          int cell = a[idxx][idxy];
          for (int bit = 0; bit < 32; bit++) {
            if (cell & (1 << bit)) {
              int x = idxx - b0, y = (idxy << 5) + bit - b1;
              if (x * x + y * y <= d) {
                ans++;
              }
            }
          }
        }
      }
    }
    printf("%d\\n", ans);
    ans = 0;
    for (int i = 0; i < 10000; i++) {
      for (int j = 0; j < 313; j++) {
        a[i][j] = 0;
      }
    }
    scanf("%d %d %d", &an, &bn, &r);
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int H = 10010 / 40;
const int W = 10010 / 40;
const double EPS = 1e-8;

int AN, BN;
double R;
int my[] = {0, -1, -1, 0, 1, 1, 1, 0, -1};
int mx[] = {0, 0, 1, 1, 1, 0, -1, -1, -1};

int distance2(P a, P b) {
  return (a.real() - b.real()) * (a.real() - b.real()) +
         (a.imag() - b.imag()) * (a.imag() - b.imag());
}

int main() {
  while (cin >> AN >> BN >> R && AN) {
    int ans = 0;
    R = R * 4;
    vector<P> v[H][W];
    REP(b, AN) {
      int x, y;
      cin >> x >> y;
      v[y / 40][x / 40].push_back(P(x, y));
    }
    REP(a, BN) {
      int x, y;
      cin >> x >> y;
      P p = P(x, y);
      REP(i, 9) {
        int ny = y / 40 + my[i], nx = x / 40 + mx[i];
        if (ny >= 0 && nx >= 0 && ny < H && nx < W) {
          REP(j, v[ny][nx].size()) {
            int d2 = distance2(p, v[ny][nx][j]);
            if (d2 <= R * R)
              ++ans;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int H = 10010 / 40;
const int W = 10010 / 40;
const double EPS = 1e-8;

int AN, BN;
double R;
int my[] = {0, -1, -1, 0, 1, 1, 1, 0, -1};
int mx[] = {0, 0, 1, 1, 1, 0, -1, -1, -1};

int main() {
  while (cin >> AN >> BN >> R && AN) {
    int ans = 0;
    R = R * 4;
    vector<P> v[H][W];
    REP(b, AN) {
      int x, y;
      cin >> x >> y;
      v[y / 40][x / 40].push_back(P(x, y));
    }
    REP(a, BN) {
      int x, y;
      cin >> x >> y;
      P p = P(x, y);
      REP(i, 9) {
        int ny = y / 40 + my[i], nx = x / 40 + mx[i];
        if (ny >= 0 && nx >= 0 && ny < H && nx < W) {
          REP(j, v[ny][nx].size()) {
            int d2 = norm(p - v[ny][nx][j]);
            if (d2 <= R * R)
              ++ans;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Runtime Error

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

typedef pair<int, int> P;

int main() {
  int AN, BN, R, x, y, d2, i, j, dx, dy, res;
  while (cin >> AN >> BN >> R, AN, BN, R) {
    P A[100001];
    P B[100001];
    vector<P> sp[300][300];
    vector<P> blo_el;
    res = 0;

    for (i = 0; i < AN; i++) {
      cin >> A[i].first >> A[i].second;
    }

    for (i = 0; i < BN; i++) {
      cin >> B[i].first >> B[i].second;
      sp[B[i].second / 40][B[i].first / 40].push_back(
          P(B[i].first, B[i].second));
    }

    for (i = 0; i < AN; i++) {
      int block_x = A[i].first / 40;
      int block_y = A[i].second / 40;
      for (dx = -1; dx <= 1; dx++) {
        for (dy = -1; dy <= 1; dy++) {
          if (block_x + dx < 0 || block_x + dx >= 250 || block_y + dy < 0 ||
              block_y + dy >= 250)
            continue;
          blo_el = sp[block_y + dy][block_x + dx];
          for (j = 0; j < blo_el.size(); j++) {
            d2 = (A[i].first - blo_el[j].first) *
                     (A[i].first - blo_el[j].first) +
                 (A[i].second - blo_el[j].second) *
                     (A[i].second - blo_el[j].second);
            if (d2 <= 16 * R * R) {
              res += 1;
            }
          }
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

typedef pair<int, int> P;

int main() {
  int AN, BN, R, x, y, d2, i, j, dx, dy;
  int res = 0;
  while (cin >> AN >> BN >> R, AN, BN, R) {
    P A[100001];
    P B[100001];
    vector<P> sp[251][251];
    vector<P> blo_el;
    for (i = 0; i < AN; i++) {
      cin >> A[i].first >> A[i].second;
    }

    for (i = 0; i < BN; i++) {
      cin >> B[i].first >> B[i].second;
      sp[B[i].second / 40][B[i].first / 40].push_back(
          P(B[i].first, B[i].second));
    }

    for (i = 0; i < AN; i++) {
      int block_x = A[i].first / 40;
      int block_y = A[i].second / 40;
      for (dx = -1; dx <= 1; dx++) {
        for (dy = -1; dy <= 1; dy++) {
          if (block_x + dx < 0 || block_x + dx >= 250 || block_y + dx < 0 ||
              block_y + dy >= 250)
            continue;
          blo_el = sp[block_y + dy][block_x + dx];
          // for (j=0; j<blo_el.size(); j++) {
          //     d2 = (A[i].first - blo_el[j].first) * (A[i].first -
          //     blo_el[j].first)
          //         + (A[i].second - blo_el[j].second) * (A[i].second -
          //         blo_el[j].second);
          //     if (d2 <= 16*R*R) {
          //         res += 1;
          //     }
          // }
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int dis2(int ax, int ay, int bx, int by) {
  return (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
}

int main() {
  int an, bn, r, ans;
  vector<int> ax[250][250], ay[250][250];
  int x, y, bx, by;
  int dx[] = {0, 0, 1, 1, 1, 0, -1, -1, -1},
      dy[] = {0, -1, -1, 0, 1, 1, 1, 0, -1};

  while (scanf("%d %d %d", &an, &bn, &r), an || bn || r) {
    for (int i = 0; i < 250; i++)
      for (int j = 0; j < 250; j++) {
        ax[i][j].clear();
        ay[i][j].clear();
      }

    for (int i = 0; i < an; i++) {
      scanf("%d %d", &x, &y);
      ax[x / 40][y / 40].push_back(x);
      ay[x / 40][y / 40].push_back(y);
    }

    ans = 0;
    for (int i = 0; i < bn; i++) {
      scanf("%d %d", &bx, &by);
      for (int i = 0; i < 9; i++) {
        x = bx / 40 + dx[i];
        y = by / 40 + dy[i];
        if (x < 0 || y < 0 || 250 <= x || 250 <= y)
          continue;
        for (int j = 0; j < (int)ax[x][y].size(); j++) {
          if (dis2(ax[x][y][j], ay[x][y][j], bx, by) <= 16 * r * r)
            ans++;
        }
      }
    }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

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

int dis2(int ax, int ay, int bx, int by) {
  return (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
}

int main() {
  int an, bn, r, ans;
  vector<int> ax[250][250], ay[250][250];
  int x, y, bx, by;
  int dx[] = {0, 0, 1, 1, 1, 0, -1, -1, -1},
      dy[] = {0, -1, -1, 0, 1, 1, 1, 0, -1};

  while (cin >> an >> bn >> r, an || bn || r) {
    for (int i = 0; i < 250; i++)
      for (int j = 0; j < 250; j++) {
        ax[i][j].clear();
        ay[i][j].clear();
      }

    for (int i = 0; i < an; i++) {
      cin >> x >> y;
      ax[x / 40][y / 40].push_back(x);
      ay[x / 40][y / 40].push_back(y);
    }

    ans = 0;
    for (int i = 0; i < bn; i++) {
      cin >> bx >> by;
      for (int i = 0; i < 9; i++) {
        x = bx / 40 + dx[i];
        y = by / 40 + dy[i];
        if (x < 0 || y < 0 || 250 <= x || 250 <= y)
          continue;
        for (int j = 0; j < (int)ax[x][y].size(); j++) {
          if (dis2(ax[x][y][j], ay[x][y][j], bx, by) <= 16 * r * r)
            ans++;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

typedef pair<int, int> P;

int dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dy[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};

int D(int x1, int y1, int x2, int y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

int main() {
  int AN, BN, R;
  while (scanf("%d %d %d", &AN, &BN, &R), AN || BN) {
    int AX[100001], AY[100001];
    vector<P> m[250][250];
    int ans = 0;

    for (int i = 0; i < AN; i++) {
      scanf("%d %d", &AX[i], &AY[i]);
    }
    for (int i = 0; i < BN; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      P p(x, y);
      m[y / 40][x / 40].push_back(p);
    }
    for (int i = 0; i < AN; i++) {
      int ax = AX[i];
      int ay = AY[i];

      for (int j = 0; j < 9; j++) {
        int mx = ax / 40 + dx[j];
        int my = ay / 40 + dy[j];
        if (mx < 0 || my < 0 || mx >= 250 || my >= 250)
          continue;
        vector<P> B = m[my][mx];
        for (int k = 0; k < B.size(); k++) {
          int bx = B[k].first;
          int by = B[k].second;
          if (D(ax, ay, bx, by) <= 16 * R * R) {
            ans++;
          }
        }
      }
    }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

typedef pair<int, int> P;

int dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dy[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};

int D(int x1, int y1, int x2, int y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

int main() {
  int AN, BN, R;
  while (scanf("%d %d", &AN, &BN), AN || BN) {
    int AX[100001], AY[100001];
    vector<P> m[600][600];
    int ans = 0;

    scanf("%d", &R);

    for (int i = 0; i < AN; i++) {
      scanf("%d %d", &AX[i], &AY[i]);
    }
    for (int i = 0; i < BN; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      P p(x, y);
      m[y / 50][x / 50].push_back(p);
    }
    for (int i = 0; i < AN; i++) {
      int ax = AX[i];
      int ay = AY[i];

      for (int j = 0; j < 9; j++) {
        int mx = ax / 50 + dx[j];
        int my = ay / 50 + dy[j];
        if (mx < 0 || my < 0 || mx >= 600 || my >= 600)
          continue;
        vector<P> B = m[my][mx];
        for (int k = 0; k < B.size(); k++) {
          int bx = B[k].first;
          int by = B[k].second;
          if (D(ax, ay, bx, by) <= 16 * R * R) {
            ans++;
          }
        }
      }
    }
    printf("%d\\n", ans);
  }
}
Problem p00609 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int a, b, R;
  while (cin >> a >> b >> R, a || b) {
    vector<long long int> A_x(a), A_y(a);
    for (int i = 0; i < a; ++i)
      cin >> A_x[i] >> A_y[i];
    vector<vector<long long int>> M(100010);
    for (int i = 0; i < b; ++i) {
      long long int x, y;
      cin >> x >> y;
      M[x].push_back(y);
    }
    for (auto &x : M)
      sort(x.begin(), x.end());
    long long int ans = 0;
    for (int i = 0; i < a; ++i) {
      long long int x = A_x[i], y = A_y[i];
      for (long long int j = max(0LL, x - 4 * R); j <= min(100000LL, x + 4 * R);
           ++j) {
        long long int d = floor(sqrt(16 * R * R - (x - j) * (x - j)) + 1e-8);
        ans += upper_bound(M[j].begin(), M[j].end(), y + d) -
               lower_bound(M[j].begin(), M[j].end(), y - d);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int a, b, R;
  while (cin >> a >> b >> R, a || b) {
    vector<long long int> A_x(a), A_y(a);
    for (int i = 0; i < a; ++i)
      cin >> A_x[i] >> A_y[i];
    vector<vector<long long int>> M(100010);
    for (int i = 0; i < b; ++i) {
      long long int x, y;
      cin >> x >> y;
      M[x].push_back(y);
    }
    for (auto &x : M)
      sort(x.begin(), x.end());
    long long int ans = 0;
    for (int i = 0; i < a; ++i) {
      long long int x = A_x[i], y = A_y[i];
      for (long long int j = x - 4 * R; j <= x + 4 * R; ++j) {
        long long int d = floor(sqrt(16 * R * R - (x - j) * (x - j)) + 1e-8);
        ans += upper_bound(M[j].begin(), M[j].end(), y + d) -
               lower_bound(M[j].begin(), M[j].end(), y - d);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#pragma warning(disable : 4996)
int n, m, r, x[100000], y[100000];
vector<int> dp[11000];
int main() {
  while (true) {
    cin >> n >> m >> r;
    if (n == 0)
      break;
    for (int i = 0; i < 11000; i++)
      dp[i].clear();
    for (int i = 0; i < n; i++)
      cin >> x[i] >> y[i];
    for (int i = 0; i < m; i++) {
      int AA, BB;
      cin >> AA >> BB;
      dp[AA].push_back(BB);
    }
    for (int i = 0; i < 11000; i++)
      sort(dp[i].begin(), dp[i].end());
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = -r * 4; j <= r * 4; j++) {
        int J = x[i] + j;
        if (J < 0)
          continue;
        int L = sqrt(r * r * 16 - j * j);
        int P1 = y[i] - L, Q1 = y[i] + L;
        int pos1 = lower_bound(dp[J].begin(), dp[J].end(), P1) - dp[J].begin();
        int pos2 =
            lower_bound(dp[J].begin(), dp[J].end(), Q1 + 1) - dp[J].begin();
        cnt += pos2 - pos1;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
#pragma warning(disable : 4996)
int n, m, r, x[100000], y[100000];
int dp[11000][650];
int main() {
  while (true) {
    cin >> n >> m >> r;
    if (n == 0)
      break;
    for (int i = 0; i < 10000; i++)
      for (int j = 0; j < 625; j++)
        dp[i][j] = 0;
    for (int i = 0; i < n; i++)
      scanf("%d%d", &x[i], &y[i]);
    for (int i = 0; i < m; i++) {
      int AA, BB;
      scanf("%d%d", &AA, &BB);
      dp[AA][BB / 16] += (1 << (BB % 16));
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = -r * 4; j <= r * 4; j++) {
        for (int k = -r * 4; k <= r * 4; k++) {
          if (j * j + k * k <= r * r * 16) {
            int XX = x[i] + j, YY = y[i] + k;
            if (XX < 0 || YY < 0)
              continue;
            int C = dp[XX][YY / 16] / (1 << (YY % 16));
            if (C % 2 == 1)
              cnt++;
          }
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
#define all(c) c.begin(), c.end()
using namespace std;
typedef pair<int, int> P;
int a, b, r;
/*bool check(int x,int y,int s,int t){
        if(){
                return true;
        }
        return false;
}*/
int main() {
  while (scanf("%d%d%d", &a, &b, &r) != EOF, a || b || r) {
    vector<P> ap(a);
    int ans = 0;
    for (int i = 0; i < a; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      // cin>>x>>y;
      ap[i] = P(y, x);
    }
    sort(all(ap));
    vector<P> pb(b);
    for (int i = 0; i < b; i++) {
      int x, y;
      // cin>>x>>y;
      scanf("%d %d", &x, &y);
      int x1 = x - 4 * r, x2 = x + 4 * r, y1 = y - 4 * r, y2 = y + 4 * r;
      int ind = lower_bound(all(ap), P(y1, x1)) - ap.begin();
      while (ind < ap.size() && ap[ind].first <= y2) {
        if (ap[ind].second > x2) {
          ind = lower_bound(all(ap), P(ap[ind].first + 1, x1)) - ap.begin();
          continue;
        }
        if (/*check(x,y,ap[ind].second,ap[ind].first)*/ (x - ap[ind].second) *
                    (x - ap[ind].second) +
                (y - ap[ind].first) * (y - ap[ind].first) <=
            16 * r * r)
          ans++;
        ind++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#define all(c) c.begin(), c.end()
using namespace std;
typedef pair<int, int> P;
int a, b, r;
/*bool check(int x,int y,int s,int t){
        if(){
                return true;
        }
        return false;
}*/
int main() {
  while (cin >> a >> b >> r, a || b || r) {
    vector<P> ap(a);
    int ans = 0;
    for (int i = 0; i < a; i++) {
      int x, y;
      cin >> x >> y;
      ap[i] = P(y, x);
    }
    sort(all(ap));
    vector<P> pb(b);
    for (int i = 0; i < b; i++) {
      int x, y;
      cin >> x >> y;
      int x1 = x - 4 * r, x2 = x + 4 * r, y1 = y - 4 * r, y2 = y + 4 * r;
      int ind = lower_bound(all(ap), P(y1, x1)) - ap.begin();
      while (ind < ap.size() && ap[ind].first <= y2) {
        if (ap[ind].second > x2) {
          ind = lower_bound(all(ap), P(ap[ind].first + 1, x1)) - ap.begin();
          continue;
        }
        if (/*check(x,y,ap[ind].second,ap[ind].first)*/ (x - ap[ind].second) *
                    (x - ap[ind].second) +
                (y - ap[ind].first) * (y - ap[ind].first) <=
            16 * r * r)
          ans++;
        ind++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}