結果

問題 No.723 2つの数の和
ユーザー danpe919danpe919
提出日時 2021-02-07 21:20:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 2,007 bytes
コンパイル時間 1,581 ms
コンパイル使用メモリ 176,592 KB
実行使用メモリ 8,040 KB
最終ジャッジ日時 2023-09-17 20:23:56
合計ジャッジ時間 4,125 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 50 ms
5,752 KB
testcase_04 AC 71 ms
6,176 KB
testcase_05 AC 56 ms
6,036 KB
testcase_06 AC 66 ms
6,264 KB
testcase_07 AC 26 ms
4,932 KB
testcase_08 AC 31 ms
5,020 KB
testcase_09 AC 64 ms
6,192 KB
testcase_10 AC 28 ms
4,868 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 34 ms
5,420 KB
testcase_13 AC 58 ms
6,696 KB
testcase_14 AC 14 ms
4,640 KB
testcase_15 AC 24 ms
4,984 KB
testcase_16 AC 37 ms
5,572 KB
testcase_17 AC 48 ms
6,024 KB
testcase_18 AC 16 ms
4,376 KB
testcase_19 AC 31 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 72 ms
8,040 KB
testcase_24 AC 18 ms
4,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, st, n) for (int i = st; i < (n); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP(i, ed, n) for (int i = (n - 1); i >= (ed); --i)
#define BIT(n, k) ((n >> k) & 1)
#define LEN(s) (int)s.size()
#define popcount(n) __builtin_popcount(n)
#define RANGE(a) a.begin(), a.end()
#define RRANGE(a) a.rbegin(), a.rend()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define dump(x) cout << #x << " = " << x << endl
#define myceil(a, b) (a + (b - 1)) / (b)
#define pow2(a) ((a) * (a))
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
const int IINF = 1e8;
const ll LINF = 1e15;
const ll mod = 1e9 + 7;
template <typename T>
istream& operator>>(istream& i, V<T>& v) {
  rep(j, LEN(v)) i >> v[j];
  return i;
}
istream& operator>>(istream& i, P& p) {
  i >> p.first >> p.second;
  return i;
}
template <typename T>
ostream& operator<<(ostream& o, V<T>& v) {
  rep(i, LEN(v)) o << v[i] << " ";
  return o;
}
ostream& operator<<(ostream& o, P p) {
  o << p.first << " " << p.second;
  return o;
}

/**
 * @brief Binary Indexed Tree
 * @note 0-indexed
 */
template <typename T>
class BinaryIndexdTree {
 public:
  int n;
  vector<T> data;
  BinaryIndexdTree(int n_) : n(n_), data(n_ + 1, 0) {}
  // i 番目に x を加算
  void add(int i, T x) {
    for (; i < n; i |= i + 1) data[i] += x;
  }
  // [left, right) の和
  T sum(int left, int right) { return sum(right) - sum(left); }
  // [0, i) の和
  T sum(int i) {
    T ret(0);
    for (i--; i >= 0; i = (i & (i + 1)) - 1) {
      ret += data[i];
    }
    return ret;
  }
};

int main() {
  int n;
  ll x;
  cin >> n >> x;
  V<int> a(n);
  cin >> a;

  map<int, int> mp;
  rep(i, n) {
    mp[a[i]]++;
  }

  ll ans = 0;
  rep(i, n) {
    ll tgt = x - a[i];
    if (mp.find(tgt) != mp.end()) {
      ans += mp[tgt];
    }
  }
  cout << ans << endl;
}
0