結果
| 問題 |
No.742 にゃんにゃんにゃん 猫の挨拶
|
| コンテスト | |
| ユーザー |
けーむ
|
| 提出日時 | 2020-08-17 17:49:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,779 bytes |
| コンパイル時間 | 1,676 ms |
| コンパイル使用メモリ | 174,176 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 11:10:13 |
| 合計ジャッジ時間 | 2,533 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }
template<typename T>
struct BinaryIndexedTree {
private:
int n;
vector<T> bit;
public:
BinaryIndexedTree(int _n) : n(_n + 1), bit(n + 1, 0){}
T sum(int idx) {
T s(0);
for(int x = idx + 1; x > 0; x -= (x & -x)) s += bit[x];
return s;
}
void add(int idx, T a) {
for(int x = idx + 1; x <= n; x += (x & -x)) bit[x] += a;
}
T query(int l, int r) {
return sum(r - 1) - sum(l - 1);
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
const ll MV = 30000;
ll n;
cin >> n;
vector<pair<ll, ll>> cat(n);
rep(i, n) {
ll m;
cin >> m;
cat[i] = make_pair(min(i + 1, m), max(i + 1, m));
}
sort(all(cat), [](const pair<ll, ll> &a, const pair<ll, ll> &b) {
if (a.first != b.first) return a.first < b.first;
return a.second > b.second;
});
BinaryIndexedTree<ll> bit(MV + 1);
ll ans = 0;
rep(i, n) {
ans += bit.query(cat[i].first + 1, MV + 1);
bit.add(cat[i].second, 1);
}
cout << ans << endl;
return 0;
}
けーむ