結果
| 問題 |
No.694 square1001 and Permutation 3
|
| コンテスト | |
| ユーザー |
e869120
|
| 提出日時 | 2018-06-08 22:31:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 306 ms / 3,000 ms |
| コード長 | 982 bytes |
| コンパイル時間 | 695 ms |
| コンパイル使用メモリ | 77,104 KB |
| 実行使用メモリ | 9,420 KB |
| 最終ジャッジ日時 | 2024-06-30 10:49:34 |
| 合計ジャッジ時間 | 4,603 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)
int bit[500009]; vector<int>vec;
void add(int pos, int x) {
pos++;
while (pos <= 500007) { bit[pos] += x; pos += (pos&-pos); }
}
int sum(int pos) {
pos++; int s = 0;
while (pos >= 1) { s += bit[pos]; pos -= (pos&-pos); }
return s;
}
int Sum(int L, int R) {
return sum(R) - sum(L - 1);
}
int n, a[500009];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]); vec.push_back(a[i]);
}
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for (int i = 1; i <= n; i++) {
a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin();
}
long long V = 0;
for (int i = 1; i <= n; i++) {
V += Sum(a[i] + 1, vec.size());
add(a[i], 1);
}
for (int i = 1; i <= n; i++) {
printf("%lld\n", V);
add(a[i], -1);
V -= Sum(0, a[i] - 1);
V += Sum(a[i] + 1, vec.size());
add(a[i], 1);
}
return 0;
}
e869120