結果

問題 No.482 あなたの名は
ユーザー yomo3
提出日時 2020-04-05 18:42:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 922 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 170,908 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-03 08:20:54
合計ジャッジ時間 4,912 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 3 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#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()
{
    int 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