結果
| 問題 |
No.1115 二つの数列 / Two Sequences
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-17 21:45:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,719 bytes |
| コンパイル時間 | 1,787 ms |
| コンパイル使用メモリ | 172,816 KB |
| 実行使用メモリ | 5,632 KB |
| 最終ジャッジ日時 | 2024-11-29 23:01:32 |
| 合計ジャッジ時間 | 3,608 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 3 |
| other | AC * 10 WA * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
struct BinaryIndexTree {
public:
BinaryIndexTree(int n)
: mN(n) {
mPow = 1;
while (mPow < n)
mPow <<= 1;
node.resize(n + 1);
REP(i, n + 1) {
node[i] = 0;
}
}
~BinaryIndexTree() {
node.resize(0);
}
//! 1-index get
ll sum(int index) {
ll sum = 0;
for (int i = index; i > 0; i -= i & (-i))
sum += node[i];
return sum;
}
//! 1-index add
void add(int index, ll value) {
for (int i = index; i <= mN; i += i & (-i))
node[i] += value;
}
int lowerBound(ll value) {
if (value <= 0)
return 0;
int x = 0;
for (int k = mPow; k > 0; k >>= 1) {
if (x + k <= mN && node[x + k] < value) {
value -= node[x + k];
x += k;
}
}
return x + 1;
}
private:
vector<ll> node;
ll mN;
ll mPow;
};
pll A[100005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
REP(i, N) {
cin >> A[i].first;
}
REP(i, N) {
cin >> A[i].second;
}
sort(A, A + N, [](pll a, pll b) {
return a.second < b.second;
});
BinaryIndexTree bit(N + 5);
ll ans = 0;
REP(i, N) {
ans += i - bit.sum(A[i].first);
bit.add(A[i].first, 1);
}
cout << ans << endl;
return 0;
}