結果

問題 No.694 square1001 and Permutation 3
ユーザー ats5515
提出日時 2018-06-08 22:28:56
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1,026 ms / 3,000 ms
コード長 1,175 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 87,444 KB
実行使用メモリ 18,784 KB
最終ジャッジ日時 2024-06-30 10:49:18
合計ジャッジ時間 8,668 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int mergecount(vector<int> &a) {
int count = 0;
int n = a.size();
if (n > 1) {
vector<int> b(a.begin(), a.begin() + n / 2);
vector<int> c(a.begin() + n / 2, a.end());
count += mergecount(b);
count += mergecount(c);
for (int i = 0, j = 0, k = 0; i < n; ++i)
if (k == c.size()) a[i] = b[j++];
else if (j == b.size()) a[i] = c[k++];
else if (b[j] <= c[k]) a[i] = b[j++];
else { a[i] = c[k++]; count += n / 2 - j; }
}
return count;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> A(N);
int res = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<int> B = A;
res = mergecount(A);
sort(A.begin(), A.end());
cout << res << endl;
for (int i = 0; i < N - 1; i++) {
int k = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
int k2 = upper_bound(A.begin(), A.end(), B[i]) - A.begin();
res -= k;
res += N - k2;
cout << res << endl;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0