結果

問題 No.1282 Display Elements
ユーザー tonyu0tonyu0
提出日時 2020-11-07 16:04:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 1,060 ms
コンパイル使用メモリ 113,604 KB
実行使用メモリ 6,288 KB
最終ジャッジ日時 2023-09-29 20:35:55
合計ジャッジ時間 3,071 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,872 KB
testcase_01 AC 3 ms
4,852 KB
testcase_02 AC 2 ms
4,612 KB
testcase_03 AC 2 ms
4,772 KB
testcase_04 AC 3 ms
4,688 KB
testcase_05 AC 3 ms
4,620 KB
testcase_06 AC 2 ms
4,500 KB
testcase_07 AC 2 ms
4,760 KB
testcase_08 AC 2 ms
4,684 KB
testcase_09 AC 3 ms
4,588 KB
testcase_10 AC 3 ms
4,620 KB
testcase_11 AC 3 ms
4,860 KB
testcase_12 AC 2 ms
4,684 KB
testcase_13 AC 2 ms
4,608 KB
testcase_14 AC 3 ms
4,596 KB
testcase_15 AC 110 ms
5,932 KB
testcase_16 AC 45 ms
5,232 KB
testcase_17 AC 93 ms
5,604 KB
testcase_18 AC 57 ms
5,548 KB
testcase_19 AC 89 ms
6,088 KB
testcase_20 AC 83 ms
6,144 KB
testcase_21 AC 121 ms
6,144 KB
testcase_22 AC 94 ms
6,288 KB
testcase_23 AC 121 ms
6,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for (int i = j; i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; j <= i; --i)

template <typename T>
class fenwick_tree {
  size_t size, depth;
  std::vector<T> data;

public:
  fenwick_tree() = default;
  explicit fenwick_tree(size_t n) : size(n), data(n) {}
  T query(int i) {
    T result = 0;
    for (; i >= 0; i = (i & i + 1) - 1) result += data[i];
    return result;
  }
  void update(int i, T x) {
    for (; i < size; i = i | i + 1) data[i] += x;
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n * 2);
  rep(i, 0, n) {
    cin >> a[i];
    c[i] = a[i];
  }
  rep(i, 0, n) {
    cin >> b[i];
    c[i + n] = b[i];
  }
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());

  sort(a.begin(), a.end());

  fenwick_tree<ll> ft(200005);
  ll ans = 0;
  rep(i, 0, n) {
    int av = lower_bound(c.begin(), c.end(), a[i]) - c.begin();
    int bv = lower_bound(c.begin(), c.end(), b[i]) - c.begin();
    ft.update(bv + 1, 1);
    ans += ft.query(av);
  }
  cout << ans << '\n';

  return 0;
}
0