結果
| 問題 | No.694 square1001 and Permutation 3 | 
| コンテスト | |
| ユーザー |  e869120 | 
| 提出日時 | 2018-06-08 22:28:55 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 311 ms / 3,000 ms | 
| コード長 | 982 bytes | 
| コンパイル時間 | 812 ms | 
| コンパイル使用メモリ | 76,824 KB | 
| 実行使用メモリ | 9,432 KB | 
| 最終ジャッジ日時 | 2024-06-30 10:48:50 | 
| 合計ジャッジ時間 | 4,719 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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;
}
            
            
            
        