結果

問題 No.482 あなたの名は
ユーザー kk
提出日時 2020-07-03 02:44:05
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 2,739 ms
コンパイル使用メモリ 201,108 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 01:01:55
合計ジャッジ時間 5,148 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 25 ms
4,352 KB
testcase_16 AC 26 ms
4,352 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 25 ms
4,348 KB
testcase_20 WA -
testcase_21 AC 25 ms
4,348 KB
testcase_22 AC 25 ms
4,348 KB
testcase_23 AC 24 ms
4,352 KB
testcase_24 WA -
testcase_25 AC 25 ms
4,348 KB
testcase_26 AC 25 ms
4,348 KB
testcase_27 AC 25 ms
4,348 KB
testcase_28 AC 25 ms
4,348 KB
testcase_29 AC 24 ms
4,348 KB
testcase_30 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

template <typename T>
class BIT {
  vector<T> bit;
public:
  BIT() {}
  // manage data in [1, n]
  BIT(int n) : bit(n + 1) {}
  
  void init() {
    fill(bit.begin(), bit.end(), 0);
  }
  
  // return sum in [1, i]
  T sum(int i){
    T s = 0;
    while(i > 0){
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
  
  // return sum in [l, r]
  T sum(int l, int r) {
    return sum(r) - sum(l-1);
  }
  
  void add(int i, T x){
    while(i < (int)bit.size()){
      bit[i] += x;
      i += i & -i;
    }
  }
};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  long long k;
  cin >> n >> k;

  BIT<int> b(n);

  long long r = 0;
  for (int i = 1; i <= n; i++) {
    int d;
    cin >> d;
    r += b.sum(d, n);
    b.add(d, 1);
  }

  if (k >= r && (k - r) % 2 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}
0