結果

問題 No.1282 Display Elements
ユーザー mfbgjsczmfbgjscz
提出日時 2020-09-15 15:25:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 303 ms / 2,000 ms
コード長 1,970 bytes
コンパイル時間 4,170 ms
コンパイル使用メモリ 218,836 KB
実行使用メモリ 25,004 KB
最終ジャッジ日時 2023-09-04 01:46:07
合計ジャッジ時間 5,606 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 277 ms
23,164 KB
testcase_16 AC 96 ms
11,368 KB
testcase_17 AC 225 ms
19,684 KB
testcase_18 AC 130 ms
13,656 KB
testcase_19 AC 118 ms
10,816 KB
testcase_20 AC 120 ms
11,036 KB
testcase_21 AC 303 ms
25,004 KB
testcase_22 AC 135 ms
10,956 KB
testcase_23 AC 303 ms
24,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define INF 9999999999999999
#define rep(i,m,n) for(ll i = m;i < n;i++)
#define rrep(i,m,n) for(ll i = m - 1; i >= n; i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(), N.end()), N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(), n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<ll,ll>
#define tint tuple<ll, ll, ll>
#define mod 998244353
#define MAX 100010
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

int main() {
    ll N, res = 0;
    cin >> N;
    vector<ll> A(N), B(N), comp;
    map<ll, ll> mp;
    multiset<ll> st;
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
    rep(i, 0, N) comp.push_back(A[i]);
    rep(i, 0, N) comp.push_back(B[i]);
    Sort(comp); UE(comp);
    rep(i, 0, comp.size()) mp[comp[i]] = i + 1;
    rep(i, 0, N) A[i] = mp[A[i]];
    rep(i, 0, N) B[i] = mp[B[i]];
    Sort(A);
    BinaryIndexedTree<ll> rs(comp.size() + 10);
    st.insert(0);
    rep(i, 0, N) {
        rs.add(B[i], 1);
        st.insert(B[i]);
        auto itr = st.lower_bound(A[i]); 
        itr--; //[1,*itr]の個数が答え
        res += rs.sum(*itr);
    }
    cout << res << endl;
}
0