結果
問題 | No.694 square1001 and Permutation 3 |
ユーザー |
|
提出日時 | 2018-09-28 13:47:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,207 ms / 3,000 ms |
コード長 | 1,373 bytes |
コンパイル時間 | 1,899 ms |
コンパイル使用メモリ | 182,332 KB |
実行使用メモリ | 44,288 KB |
最終ジャッジ日時 | 2024-10-12 04:48:48 |
合計ジャッジ時間 | 13,859 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 13 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;//引数unzipには圧縮前のvectorを入れるint compress(vector<ll>& unzip, map<ll, int>& zip) {sort(unzip.begin(), unzip.end());unzip.erase(unique(unzip.begin(), unzip.end()), unzip.end());for (int i = 0; i < unzip.size(); i++) {zip[unzip[i]] = i;}return unzip.size();}//1-indexであることに注意template <typename T>struct BIT {int n;vector<T> data;BIT(int n) : n(n), data(n + 1, 0) {}T sum(int i) {T s = 0;while (i > 0) {s += data[i];i -= i & -i;}return s;}void add(int i, T x) {while (i <= n) {data[i] += x;i += i & -i;}}};int main() {cin.tie(0);ios::sync_with_stdio(false);int n;cin >> n;vector<ll> a(n);for (int i = 0; i < n; i++) cin >> a[i];vector<ll> unzip(a);map<ll, int> zip;compress(unzip, zip);ll ans = 0;BIT<int> b(unzip.size());for (int i = 0; i < n; i++) {ans += i - b.sum(zip[a[i]] + 1);b.add((zip[a[i]] + 1), 1);}cout << ans << endl;for (int i = 0; i < n - 1; i++) {ans -= b.sum(zip[a[i]]);ans += n - b.sum(zip[a[i]] + 1);cout << ans << endl;}return 0;}