結果

問題 No.1282 Display Elements
ユーザー 0w10w1
提出日時 2020-12-28 16:35:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,447 bytes
コンパイル時間 2,545 ms
コンパイル使用メモリ 207,112 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 09:54:12
合計ジャッジ時間 4,929 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 74 ms
6,944 KB
testcase_16 AC 28 ms
6,940 KB
testcase_17 AC 60 ms
6,944 KB
testcase_18 AC 37 ms
6,944 KB
testcase_19 AC 39 ms
6,944 KB
testcase_20 AC 38 ms
6,940 KB
testcase_21 AC 82 ms
6,944 KB
testcase_22 AC 51 ms
6,944 KB
testcase_23 AC 81 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T>
vector<T> concat(vector<T> a, vector<T> b) {
  a.insert(a.end(), b.begin(), b.end());
  return a;
}

template<typename T, T zero>
struct Ftree {
  vector<T> dat;
  function<T(T, T)> fadd;
  Ftree(int n, function<T(T, T)> f) : dat(n + 1, zero), fadd(f) {}
  void add(int x, T v) {
    for (int i = 1 + x; i < dat.size(); i += i & -i) dat[i] = fadd(dat[i], v);
  }
  T sum(int x) {
    T r = zero;
    for (int i = 1 + x; i; i -= i & -i) r = fadd(r, dat[i]);
    return r;
  }
};

template<typename T>
struct Compress {
  vector<T> dat;
  Compress(vector<T> d) : dat(d) {
    sort(dat.begin(), dat.end());
    dat.erase(unique(dat.begin(), dat.end()), dat.end());
  }
  int operator()(const T &v) { return lower_bound(dat.begin(), dat.end(), v) - dat.begin(); }
  T operator[](int x) { return dat[x]; }
  int size() { return dat.size(); }
};

int main() {
  ios::sync_with_stdio(false);

  int N; { cin >> N; }

  vector<int> A(N); { for (int i = 0; i < N; ++i) cin >> A[i]; }

  vector<int> B(N); { for (int i = 0; i < N; ++i) cin >> B[i]; }

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

  Compress cps(concat(A, B));

  int64_t res = 0; {
    function<int(int, int)> fadd = [](int a, int b) { return a + b; };
    Ftree<int, 0> ftree(cps.size(), fadd);
    for (int i = 0; i < N; ++i) {
      ftree.add(cps(B[i]), +1);
      res += ftree.sum(cps(A[i]) - 1);
    }
  }

  cout << res << endl;
}

0