結果
問題 | No.559 swapAB列 |
ユーザー |
![]() |
提出日時 | 2017-08-25 22:40:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,055 bytes |
コンパイル時間 | 1,731 ms |
コンパイル使用メモリ | 171,560 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 16:03:39 |
合計ジャッジ時間 | 1,936 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 |
ソースコード
#include <bits/stdc++.h>namespace ac {using namespace std;}#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))#define all(r) r.begin(),r.end()using namespace std;using namespace ac;typedef int64_t ll;typedef vector<ll> vll;namespace ac {// FenwickTree繝サBitstruct BinaryIndexedTree {int n;vector<int64_t> b; // [1, m_n]BinaryIndexedTree() {}void init(int a_n) {n = a_n;b.resize(n + 1, 0);}int64_t sum(int i) {int64_t s = 0;while (0 < i) {s += b[i];i -= i & -i;}return s;}void add(int i, int64_t x) {while (i <= n) {b[i] += x;i += i & -i;}}};struct Inversion {int n;ac::BinaryIndexedTree bit;Inversion(int a_n) {init(a_n);}void init(int a_n) {n = a_n;bit.init(n);}vector<int64_t> getGreaterThan(vector<int64_t> &a_v) {int length = a_v.size();vector<int64_t> ord(length);for (int i = length - 1; i >= 0; i--) {ord[i] = bit.sum(a_v[i]);bit.add(a_v[i] + 1, 1);}return ord;}};}struct Solution {void solve(std::istream& in, std::ostream& out) {string S;in >> S;Inversion i(S.size());vll a(S.size());rep(i, S.size()) {a[i] = S[i] - 'A';}vll res = i.getGreaterThan(a);ll ans = accumulate(all(res), 0);out << ans << '\n';}};void solve(std::istream& in, std::ostream& out) {out << std::setprecision(12);Solution solution;solution.solve(in, out);}#include <fstream>#include <iostream>int main() {ios_base::sync_with_stdio(0);cin.tie(0);istream& in = cin;ostream& out = cout;solve(in, out);return 0;}