結果
問題 | No.1282 Display Elements |
ユーザー | milanis48663220 |
提出日時 | 2020-11-06 21:43:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 244 ms / 2,000 ms |
コード長 | 1,369 bytes |
コンパイル時間 | 867 ms |
コンパイル使用メモリ | 97,840 KB |
実行使用メモリ | 26,792 KB |
最終ジャッジ日時 | 2023-09-29 18:30:35 |
合計ジャッジ時間 | 3,238 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,384 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,376 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 | 1 ms
4,380 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 1 ms
4,376 KB |
testcase_13 | AC | 1 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | AC | 213 ms
24,892 KB |
testcase_16 | AC | 72 ms
12,004 KB |
testcase_17 | AC | 181 ms
22,764 KB |
testcase_18 | AC | 97 ms
14,528 KB |
testcase_19 | AC | 29 ms
5,080 KB |
testcase_20 | AC | 26 ms
4,964 KB |
testcase_21 | AC | 244 ms
26,792 KB |
testcase_22 | AC | 37 ms
5,092 KB |
testcase_23 | AC | 238 ms
26,788 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> using namespace std; typedef long long ll; template <typename T> struct bit{ int n; vector<T> data; bit(int n_){ n = 1; while(n < n_) n *= 2; data = vector<T>(n+1); for(int i = 0; i <= n; i++) data[i] = 0; } T sum(int i){ T ret = 0; while(i > 0){ ret += data[i]; i -= i&-i; } return ret; } void add(int i, T x){ while(i <= n){ data[i] += x; i += i&-i; } } }; ll n; ll a[100000], b[100000]; map<ll, int> compress; void make_compress(){ set<ll> st; for(int i = 0; i < n; i++){ st.insert(a[i]); st.insert(b[i]); } int cur = 1; for(ll x : st){ compress[x] = cur; cur++; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; make_compress(); sort(a, a+n); int m = compress.size(); bit<ll> bt(m); ll ans = 0; for(int i = 0; i < n; i++){ bt.add(compress[b[i]], 1); ans += bt.sum(compress[a[i]]-1); } cout << ans << endl; }