結果

問題 No.482 あなたの名は
コンテスト
ユーザー yomo3
提出日時 2020-04-05 19:23:06
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 966 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 987 ms
コンパイル使用メモリ 182,612 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-25 05:58:51
合計ジャッジ時間 2,871 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

template<class T> class BIT {
private:
    vector<T> bit;
public:
    BIT(int n) : bit(vector<T>(n+1, 0)) {}
    int sum(int i) {
        if (!i) return 0;
        return bit[i] + sum(i-(i&-i));
    }
    void add(int i, int x) {
        if (i > size()) return;
        bit[i] += x;
        add(i+(i&-i), x);
    }
    int size() const { return bit.size()-1; }
};

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

    ll N, K; cin >> N >> K;
    vector<int> D(N); cin >> D;
    BIT<int> bit(N);

    int c = 0;
    for (auto d : D) {
        c += bit.sum(N) - bit.sum(d-1);
        bit.add(d, 1);
    }
    bool ok = (c <= K && (c&1) == (K&1));
    cout << (ok ? "YES" : "NO") << endl;
}
0