結果
| 問題 | No.482 あなたの名は | 
| コンテスト | |
| ユーザー |  misora192 | 
| 提出日時 | 2020-08-07 08:56:11 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,054 bytes | 
| コンパイル時間 | 1,645 ms | 
| コンパイル使用メモリ | 168,500 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-09-22 16:51:07 | 
| 合計ジャッジ時間 | 4,272 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 WA * 12 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
// class
const int max_n  = 202020;
class BinaryIndexedTree{
private:
	int n;
	ll bit[max_n];
public:
	BinaryIndexedTree(int n){
		this -> n = n;
	}
    ll sum(int i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & (-i);
        }
        return s;
    }
    void add(int i, ll x){
        while(i <= n){
            bit[i] += x;
            i += i & (-i);
        }
    }
};
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	BinaryIndexedTree bit(n);
	ll ans = 0;
	rep(i, n){
		ans += i - bit.sum(a[i]);
		bit.add(a[i], 1);
	}
	if(ans <= k){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}
            
            
            
        