結果

問題 No.1282 Display Elements
ユーザー tonyu0tonyu0
提出日時 2020-11-07 16:02:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,445 bytes
コンパイル時間 1,005 ms
コンパイル使用メモリ 111,108 KB
実行使用メモリ 5,704 KB
最終ジャッジ日時 2023-09-29 20:35:52
合計ジャッジ時間 3,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 44 ms
4,444 KB
testcase_17 AC 92 ms
4,900 KB
testcase_18 AC 57 ms
4,592 KB
testcase_19 AC 87 ms
5,416 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

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)

[[maybe_unused]] constexpr ll MOD = 1000000007;
[[maybe_unused]] constexpr int INF = 0x3f3f3f3f;
[[maybe_unused]] constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

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<int> ft(200005);
  int 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