結果

問題 No.2089 置換の符号
ユーザー houren
提出日時 2022-09-30 23:04:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,044 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 167,956 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 00:47:11
合計ジャッジ時間 2,809 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
template <typename T>
struct BIT{
    int n;
    vector<T> data;
    BIT(int n=0) : n(n), data(n+1){}
    T sum(int i){
        T res = 0;
        for(; i; i -= i&-i){
            res += data[i];
        }
        return res;
    }
    void add(int i, T x){
        for(; i <= n; i += i&-i){
            data[i] += x;
        }
    }
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, x = 0;
    cin >> n;
    BIT<int> bit(n);
    rep(i,n) bit.add(i+1, 1);
    rep(i,n){
        int a;
        cin >> a;
        bit.add(a,-1);
        x += bit.sum(a);
    }
    cout << 1 - (x==1)*2 << '\n';
    return 0;
}
0