Submission #501080

# Submission time Handle Problem Language Result Execution time Memory
501080 2022-01-02T10:40:33 Z 600Mihnea Pairs (IOI07_pairs) C++17
37 / 100
4000 ms 8772 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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


  int B;
  cin >> B;
  ///assert(B == 1 || B == 2 || B == 3);

  if (B == 1) {
    int n, d, _;
    cin >> n >> d >> _;
    vector<int> a(n);
    for (auto &x : a) {
      cin >> x;
    }
    sort(a.begin(), a.end());
    ll sol = 0;
    int C = 0, c = 0;
    for (int i = 0; i < n; i++) {
      int low = a[i] - d, high = a[i] + d;
      while (C < n && a[C] <= high) {
        C++;
      }
      while (c < n && a[c] < low) {
        c++;
      }
      sol += C - c;
    }
    sol -= n;
    sol /= 2;
    cout << sol << "\n";
    exit(0);
  }
  if (B == 2) {
    /// aib 2d
    int n, d, L;
    cin >> n >> d >> L;
    L *= 2;
    vector<map<int, int>> aib(L + 1);

    function<int(int, int)> get = [&] (int a, int b) {
      if (a < 0) a = 0;
      if (b < 0) b = 0;
      if (a > L) a = L;
      if (b > L) b = L;
      int sol = 0;
      for (int i = a; i >= 1; i -= i & (-i)) {
        for (int j = b; j >= 1; j -= j & (-j)) {
          if (aib[i].count(j)) {
            sol += aib[i][j];
          }
        }
      }
      return sol;
    };

    function<void(int, int, int)> add = [&] (int a, int b, int x) {
      for (int i = a; i <= L; i += i & (-i)) {
        for (int j = b; j <= L; j += j & (-j)) {
          aib[i][j] += x;
        }
      }
    };

    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) {
      int xx, yy;
      cin >> xx >> yy;
      x[i] = xx + yy;
      y[i] = xx - yy;
    }

    ll sol = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        sol += (max(abs(x[i] - x[j]), abs(y[i] - y[j])) <= d);
      }
    }
    sol -= n;
    sol /= 2;
    cout << sol << "\n";
    exit(0);
  }
  assert(0);

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 716 KB Output is correct
2 Correct 11 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 716 KB Output is correct
2 Correct 16 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 588 KB Output is correct
2 Correct 23 ms 716 KB Output is correct
3 Correct 19 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7372 KB Output is correct
2 Correct 5 ms 7352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4046 ms 1612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4059 ms 1892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4067 ms 8772 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -