Submission #44476300


Source Code Expand

// clang-format off
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REPI,_REP,)(__VA_ARGS__)
#define _RREP(i,n) RREPI(i,n,0)
#define RREPI(i,a,b) for(int i=int(a);i>=int(b);--i)
#define RREP(...) _overload3(__VA_ARGS__,RREPI,_RREP,)(__VA_ARGS__)
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
typedef long long ll;
const int INF32 = 1001001001;
const long long INF64 = 1001001001001001001;
struct Init { Init() { ios::sync_with_stdio(0); cin.tie(0); cout << setprecision(15); }} init;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<class T> T gcd(T x, T y){ return (x % y) ? gcd(y, x % y) : y; }
template<class T> T lcm(T x, T y){ return x / gcd(x, y) * y; }
template<class T, class... Ts> void output(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class T> void output(vector<T> v) { for (auto u : v) cout << u << ' '; cout << '\n'; };
void yesno(bool is_ok) { cout << (is_ok ? "yes" : "no") << '\n'; }
void YesNo(bool is_ok) { cout << (is_ok ? "Yes" : "No") << '\n'; }
void YESNO(bool is_ok) { cout << (is_ok ? "YES" : "NO") << '\n'; }

// clang-format on
template <class T> long long inversion_number(const vector<T> &a) {
    auto b = a;
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    fenwick_tree<long long> ft((int)b.size());
    long long ans = 0;
    int n = (int)a.size();
    for (int i = 0; i < n; ++i) {
        int rank = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
        ans += i - ft.sum(0, rank + 1);
        ft.add(rank, 1);
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    output(inversion_number(a));
}

Submission Info

Submission Time
Task B59 - Number of Inversions
User noko206
Language C++ (GCC 9.2.1)
Score 1000
Code Size 2186 Byte
Status AC
Exec Time 53 ms
Memory 5600 KiB

Compile Error

./Main.cpp: In instantiation of ‘void output(const T&, const Ts& ...) [with T = long long int; Ts = {}]’:
./Main.cpp:53:31:   required from here
./Main.cpp:26:86: warning: statement has no effect [-Wunused-value]
   26 | template<class T, class... Ts> void output(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
      |                                                                                      ^~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 2
AC × 18
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All min_01.txt, min_02.txt, min_03.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, sample_01.txt, sample_02.txt, special_01.txt, special_02.txt, special_03.txt, special_04.txt, special_05.txt, special_06.txt, special_07.txt, special_08.txt
Case Name Status Exec Time Memory
min_01.txt AC 8 ms 3632 KiB
min_02.txt AC 2 ms 3632 KiB
min_03.txt AC 2 ms 3504 KiB
random_01.txt AC 53 ms 5596 KiB
random_02.txt AC 48 ms 5600 KiB
random_03.txt AC 47 ms 5220 KiB
random_04.txt AC 44 ms 5288 KiB
random_05.txt AC 47 ms 5220 KiB
sample_01.txt AC 2 ms 3600 KiB
sample_02.txt AC 2 ms 3472 KiB
special_01.txt AC 33 ms 5596 KiB
special_02.txt AC 33 ms 5480 KiB
special_03.txt AC 31 ms 5596 KiB
special_04.txt AC 39 ms 5444 KiB
special_05.txt AC 36 ms 5384 KiB
special_06.txt AC 37 ms 5508 KiB
special_07.txt AC 38 ms 5552 KiB
special_08.txt AC 37 ms 5444 KiB