結果

問題 No.1687 What the Heck?
ユーザー houren
提出日時 2021-09-24 21:52:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 584 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 169,372 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 10:27:16
合計ジャッジ時間 2,886 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 2 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()

int main(){
    ll n;
    cin >> n;
    vector<int> p(n), pinv(n);
    rep(i,n){
        cin >> p[i]; p[i]--;
        pinv[p[i]] = i;
    }
    ll ans = 0;
    vector<bool> used(n,false);
    rep(i,n-1){
        if(pinv[n-1-i] < pinv[n-2-i]){
            ans -= (pinv[n-i-1] + 1) * 2;
            ans += (n-i+1) * (n-i) / 2;
        }
    }
    cout << ans << endl;
    return 0;
}
0