結果
問題 | No.1282 Display Elements |
ユーザー | nawawan |
提出日時 | 2020-11-06 22:22:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 234 ms / 2,000 ms |
コード長 | 1,660 bytes |
コンパイル時間 | 1,069 ms |
コンパイル使用メモリ | 98,040 KB |
実行使用メモリ | 23,032 KB |
最終ジャッジ日時 | 2023-09-29 19:03:02 |
合計ジャッジ時間 | 3,529 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
11,216 KB |
testcase_01 | AC | 5 ms
11,360 KB |
testcase_02 | AC | 6 ms
11,312 KB |
testcase_03 | AC | 5 ms
11,220 KB |
testcase_04 | AC | 5 ms
11,216 KB |
testcase_05 | AC | 5 ms
11,220 KB |
testcase_06 | AC | 5 ms
11,252 KB |
testcase_07 | AC | 6 ms
11,312 KB |
testcase_08 | AC | 5 ms
11,232 KB |
testcase_09 | AC | 5 ms
11,312 KB |
testcase_10 | AC | 5 ms
11,360 KB |
testcase_11 | AC | 6 ms
11,304 KB |
testcase_12 | AC | 5 ms
11,312 KB |
testcase_13 | AC | 6 ms
11,248 KB |
testcase_14 | AC | 6 ms
11,364 KB |
testcase_15 | AC | 210 ms
22,132 KB |
testcase_16 | AC | 70 ms
15,460 KB |
testcase_17 | AC | 166 ms
20,004 KB |
testcase_18 | AC | 95 ms
16,652 KB |
testcase_19 | AC | 44 ms
14,000 KB |
testcase_20 | AC | 43 ms
13,940 KB |
testcase_21 | AC | 234 ms
23,024 KB |
testcase_22 | AC | 54 ms
13,792 KB |
testcase_23 | AC | 225 ms
23,032 KB |
ソースコード
#include <iostream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <map> using namespace std; struct segK{//非再帰 int n; long long MIN; int size; vector<long long> dat; segK(int n_){ n = 1; MIN = 0; size = n_; while(n < n_) n *= 2; dat.resize(2 * n); for(int i = 1; i < 2 * n; i++) dat[i] = MIN; } void update(int k, long long a){ k += n; dat[k] += a; while(k > 0){ k >>= 1; dat[k] = dat[k << 1 | 0] + dat[k << 1 | 1]; } } long long query(int l, int r){ long long res = 0; l += n; r += n; while(r > l){ if(l & 1) res += dat[l++]; if(r & 1) res += dat[--r]; l >>= 1; r >>= 1; } return res; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; segK seg(400010); vector<long long> a(N), b(N); for(int i = 0; i < N; i++) cin >> a[i]; for(int i = 0; i < N; i++) cin >> b[i]; map<int, int> m; vector<int> vec; for(int i = 0; i < N; i++){ vec.push_back(a[i]); vec.push_back(b[i]); } sort(vec.begin(), vec.end()); int index = 1; for(int i = 0; i < 2 * N; i++){ if(m.count(vec[i])) continue; m[vec[i]] = index; index++; } long long cnt = 0; sort(a.begin(), a.end()); for(int i = 0; i < N; i++){ int ind = m[b[i]]; seg.update(ind, 1); int ind2 = m[a[i]]; cnt += seg.query(0, ind2); } cout << cnt << endl; }