結果

問題 No.1282 Display Elements
ユーザー どららどらら
提出日時 2020-11-06 23:26:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 1,149 bytes
コンパイル時間 1,673 ms
コンパイル使用メモリ 178,576 KB
実行使用メモリ 23,492 KB
最終ジャッジ日時 2023-09-29 19:40:46
合計ジャッジ時間 4,657 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 297 ms
21,728 KB
testcase_16 AC 95 ms
10,612 KB
testcase_17 AC 232 ms
18,692 KB
testcase_18 AC 129 ms
12,708 KB
testcase_19 AC 83 ms
4,376 KB
testcase_20 AC 78 ms
4,384 KB
testcase_21 AC 327 ms
23,492 KB
testcase_22 AC 94 ms
4,376 KB
testcase_23 AC 327 ms
23,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

template<class T>
struct FenwickTree{
  int n;
  vector<T> tree;
public:
  FenwickTree(int n):n(n), tree(n+1, T(0)){}
  void add(int i, T value){
    for(; i<n; i|=i+1) tree[i] += value;
  }
  T sum(int i){
    T s = 0;
    for(; i>=0; i=(i&i+1)-1) s += tree[i];
    return s;
  }
};

int main(){
  int N;
  cin >> N;
  vector<int> v, w;
  map<int,int> memo;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
    memo[a] = 1;
  }
  rep(i,N){
    int a;
    cin >> a;
    w.push_back(a);
    memo[a] = 1;
  }

  map<int,int> val2id;
  int idx = 0;
  FOR(it,memo){
    val2id[it->first] = idx;
    idx++;
  }
  
  sort(ALLOF(v));

  FenwickTree<int> ft(val2id.size()+5);
  
  ll ret = 0;
  rep(i,N){
    ft.add(val2id[w[i]], 1);
    if(val2id[v[i]] > 0){
      ret += ft.sum(val2id[v[i]]-1);
    }
  }

  cout << ret << endl;
  
  return 0;
}
0