結果

問題 No.694 square1001 and Permutation 3
ユーザー firiexp
提出日時 2019-11-15 13:32:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 293 ms / 3,000 ms
コード長 1,418 bytes
コンパイル時間 1,177 ms
コンパイル使用メモリ 101,860 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-11-14 21:51:00
合計ジャッジ時間 5,937 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

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

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <limits>
static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
template<class T>
class BIT {
vector<T> bit;
public:
BIT(int n): bit(vector<T>(n+1, 0)){}
T sum(int k){
T ret = 0;
for (++k; k > 0; k -= (k & -k)) ret += bit[k];
return ret;
}
void add(int k, T x){
for (++k; k < bit.size(); k += (k & -k)) bit[k] += x;
}
};
int main() {
int n;
cin >> n;
vector<int> v(n);
for (auto &&i : v) scanf("%d", &i);
auto u = v;
sort(u.begin(), u.end());
u.erase(unique(u.begin(), u.end()), u.end());
for (int i = 0; i < n; ++i) {
v[i] = lower_bound(u.begin(),u.end(), v[i])-u.begin();
}
BIT<int> bit(n);
ll ans = 0;
for (int i = 0; i < n; ++i) {
ans += i-bit.sum(v[i]);
bit.add(v[i], 1);
}
vector<int> S(u.size()+1);
for (int i = 0; i < n; ++i) {
S[v[i]+1]++;
}
for (int i = 0; i < u.size(); ++i) {
S[i+1] += S[i];
}
for (int i = 0; i < n; ++i) {
printf("%lld\n", ans);
ans += (n-S[v[i]+1]-S[v[i]]);
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0