結果

問題 No.1282 Display Elements
ユーザー simansiman
提出日時 2022-03-21 05:12:52
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,241 bytes
コンパイル時間 2,240 ms
コンパイル使用メモリ 144,896 KB
実行使用メモリ 23,548 KB
最終ジャッジ日時 2024-04-16 21:59:45
合計ジャッジ時間 6,822 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

class BinaryIndexTree {
public:
  vector <ll> bit;
  int N;

  BinaryIndexTree(int n) {
    N = n;

    for (int i = 0; i <= N; ++i) {
      bit.push_back(0);
    }
  }

  ll sum(int i) {
    ll ret = 0;

    while (i > 0) {
      ret += bit[i];
      i -= i & -i;
    }

    return ret;
  }

  void add(int i, ll x) {
    while (i <= N) {
      bit[i] += x;
      i += i & -i;
    }
  }
};

int main() {
  int N;
  cin >> N;

  vector<int> A(N);
  vector<int> B(N);
  set<int> S;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    S.insert(A[i]);
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
    S.insert(B[i]);
  }

  BinaryIndexTree bit(N + 2);
  map<int, int> M;
  int idx = 1;
  for (int s : S) {
    M[s] = idx;
    ++idx;
  }

  sort(A.begin(), A.end());
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    int a = A[i];
    int b = B[i];
    int a_idx = M[a];
    int b_idx = M[b];
    bit.add(b_idx, 1);

    ans += bit.sum(a_idx - 1);
  }

  cout << ans << endl;

  return 0;
}
0