Submission #3725128


Source Code Expand

#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (a).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define dump(x) cerr << #x << " = " << (x) << endl;
#define dumpi(i, x) cerr << string((i), ' ') << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
using pii = pair<int, int>;
constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr double EPS = 1e-10;

struct BIT {
  int n;
  vector<int> bit;
  BIT() {}
  BIT(int n, int e = 0) {
    build(n, e);
  }
  void build(int n_, int e = 0) {
    n = n_ + 1;
    bit.resize(n, e);
  }
  void add(int k, int x) {
    while (k <= n) {
      bit[k] += x;
      k += k & -k;
    }
  }
  int sum(int k) {
    int r = 0;
    while (k > 0) {
      r += bit[k];
      k -= k & -k;
    }
    return r;
  }
  int &operator[](int i) {
    return bit[i];
  }
};

int N;
int B[100010], RB[100010];
BIT bitL, bitR;
int L[100010], R[100010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  rep(i, 0, N) {
    cin >> B[i];
    RB[i] = B[i];
  }
  reverse(RB, RB+N);
  bitL.build(N);
  bitR.build(N);
  rep(i, 0, N) {
    L[B[i]] = i - bitL.sum(B[i]);
    bitL.add(B[i], 1);
    R[RB[i]] = i - bitR.sum(RB[i]);
    bitR.add(RB[i], 1);
  }
  int ans = 0;
  rep(i, 1, N+1) {
    ans += min(L[i], R[i]);
  }
  cout << ans << endl;

  return 0;
}

Submission Info

Submission Time
Task C - 積み木
User legosuke
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1712 Byte
Status AC
Exec Time 20 ms
Memory 4992 KB

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 30 / 30 70 / 70
Status
AC × 3
AC × 33
AC × 68
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
Subtask1 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 10_small_00.txt, 10_small_01.txt, 10_small_02.txt, 10_small_03.txt, 10_small_04.txt, 10_small_05.txt, 10_small_06.txt, 10_small_07.txt, 10_small_08.txt, 10_small_09.txt, 10_small_10.txt, 10_small_11.txt, 10_small_12.txt, 10_small_13.txt, 10_small_14.txt, 10_small_15.txt, 10_small_16.txt, 10_small_17.txt, 10_small_18.txt, 10_small_19.txt, 10_small_20.txt, 10_small_21.txt, 10_small_22.txt, 10_small_23.txt, 10_small_24.txt, 10_small_25.txt, 10_small_26.txt, 10_small_27.txt, 10_small_28.txt, 10_small_29.txt
Subtask2 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 10_small_00.txt, 10_small_01.txt, 10_small_02.txt, 10_small_03.txt, 10_small_04.txt, 10_small_05.txt, 10_small_06.txt, 10_small_07.txt, 10_small_08.txt, 10_small_09.txt, 10_small_10.txt, 10_small_11.txt, 10_small_12.txt, 10_small_13.txt, 10_small_14.txt, 10_small_15.txt, 10_small_16.txt, 10_small_17.txt, 10_small_18.txt, 10_small_19.txt, 10_small_20.txt, 10_small_21.txt, 10_small_22.txt, 10_small_23.txt, 10_small_24.txt, 10_small_25.txt, 10_small_26.txt, 10_small_27.txt, 10_small_28.txt, 10_small_29.txt, 20_rand_00.txt, 20_rand_01.txt, 20_rand_02.txt, 20_rand_03.txt, 20_rand_04.txt, 20_rand_05.txt, 20_rand_06.txt, 20_rand_07.txt, 20_rand_08.txt, 20_rand_09.txt, 20_rand_10.txt, 20_rand_11.txt, 20_rand_12.txt, 20_rand_13.txt, 20_rand_14.txt, 20_rand_15.txt, 20_rand_16.txt, 20_rand_17.txt, 20_rand_18.txt, 20_rand_19.txt, 20_rand_20.txt, 20_rand_21.txt, 20_rand_22.txt, 20_rand_23.txt, 20_rand_24.txt, 20_rand_25.txt, 20_rand_26.txt, 20_rand_27.txt, 20_rand_28.txt, 20_rand_29.txt, 30_max_0.txt, 30_max_1.txt, 30_max_2.txt, 30_max_3.txt, 30_max_4.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 256 KB
00_sample_01.txt AC 1 ms 256 KB
00_sample_02.txt AC 1 ms 256 KB
10_small_00.txt AC 1 ms 256 KB
10_small_01.txt AC 1 ms 256 KB
10_small_02.txt AC 1 ms 256 KB
10_small_03.txt AC 1 ms 256 KB
10_small_04.txt AC 1 ms 256 KB
10_small_05.txt AC 1 ms 256 KB
10_small_06.txt AC 1 ms 256 KB
10_small_07.txt AC 1 ms 256 KB
10_small_08.txt AC 1 ms 256 KB
10_small_09.txt AC 1 ms 256 KB
10_small_10.txt AC 1 ms 256 KB
10_small_11.txt AC 1 ms 256 KB
10_small_12.txt AC 1 ms 256 KB
10_small_13.txt AC 1 ms 256 KB
10_small_14.txt AC 1 ms 256 KB
10_small_15.txt AC 1 ms 256 KB
10_small_16.txt AC 1 ms 256 KB
10_small_17.txt AC 1 ms 256 KB
10_small_18.txt AC 1 ms 256 KB
10_small_19.txt AC 1 ms 256 KB
10_small_20.txt AC 1 ms 256 KB
10_small_21.txt AC 1 ms 256 KB
10_small_22.txt AC 1 ms 256 KB
10_small_23.txt AC 1 ms 256 KB
10_small_24.txt AC 1 ms 256 KB
10_small_25.txt AC 1 ms 256 KB
10_small_26.txt AC 1 ms 256 KB
10_small_27.txt AC 1 ms 256 KB
10_small_28.txt AC 1 ms 256 KB
10_small_29.txt AC 1 ms 256 KB
20_rand_00.txt AC 12 ms 3200 KB
20_rand_01.txt AC 2 ms 640 KB
20_rand_02.txt AC 4 ms 1152 KB
20_rand_03.txt AC 6 ms 1664 KB
20_rand_04.txt AC 13 ms 3328 KB
20_rand_05.txt AC 17 ms 4480 KB
20_rand_06.txt AC 19 ms 4736 KB
20_rand_07.txt AC 14 ms 3456 KB
20_rand_08.txt AC 4 ms 1152 KB
20_rand_09.txt AC 3 ms 896 KB
20_rand_10.txt AC 12 ms 3200 KB
20_rand_11.txt AC 6 ms 1664 KB
20_rand_12.txt AC 6 ms 1664 KB
20_rand_13.txt AC 8 ms 2048 KB
20_rand_14.txt AC 5 ms 1408 KB
20_rand_15.txt AC 2 ms 512 KB
20_rand_16.txt AC 8 ms 2304 KB
20_rand_17.txt AC 2 ms 384 KB
20_rand_18.txt AC 20 ms 4864 KB
20_rand_19.txt AC 4 ms 1152 KB
20_rand_20.txt AC 3 ms 896 KB
20_rand_21.txt AC 12 ms 3200 KB
20_rand_22.txt AC 12 ms 3328 KB
20_rand_23.txt AC 19 ms 4736 KB
20_rand_24.txt AC 9 ms 2304 KB
20_rand_25.txt AC 9 ms 2560 KB
20_rand_26.txt AC 7 ms 1792 KB
20_rand_27.txt AC 7 ms 1920 KB
20_rand_28.txt AC 16 ms 3968 KB
20_rand_29.txt AC 3 ms 896 KB
30_max_0.txt AC 16 ms 4992 KB
30_max_1.txt AC 16 ms 4992 KB
30_max_2.txt AC 16 ms 4992 KB
30_max_3.txt AC 16 ms 4992 KB
30_max_4.txt AC 16 ms 4992 KB