結果

問題 No.1188 レベルX門松列
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-08-22 15:00:48
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,471 bytes
コンパイル時間 1,302 ms
コンパイル使用メモリ 137,992 KB
実行使用メモリ 161,868 KB
最終ジャッジ日時 2024-04-23 09:23:58
合計ジャッジ時間 3,506 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 WA -
testcase_05 AC 2 ms
6,944 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 14 ms
6,944 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

class BIT {
    int64 n;
    vector<int64> d;
public:
    BIT(int64 _n=0) {n=_n; d=vector<int64>(n+1);}
    void add(int64 i, int64 x=1) { for (i++; i <= n; i += i&-i) d[i] += x; }
    int64 sum(int64 i) { int64 x = 0; for (i++; i; i -= i&-i) x += d[i]; return x; }
};

int main() {
    int64 n;
    cin >> n;
    vector a(n,0LL);
    int64 a_max = 0;
    for (int64 i=0; i<n; i++) {
        cin >> a[i];
        a_max = max(a_max, a[i]);
    }

    BIT bit1(a_max+10);
    vector l(n,0LL);
    for (int64 i=0; i<n; i++) {
        l[i] = i - bit1.sum(a[i]);
        bit1.add(a[i]);
    }

    BIT bit2(a_max+10);
    vector r(n,0LL);
    for (int64 i=n-1; i>=0; i--) {
        r[n-1-i] = (n-1-i) - bit2.sum(a[i]);
        bit2.add(a[i]);
    }

    int64 ans = 0;
    for (int i=1; i<n-1; i++) {
        ans = max(ans, min(l[i], r[i]));
        ans = max(ans, min(n/2-l[i], n/2-r[i]));
    }

    cout << ans << endl;
}
0