結果

問題 No.1031 いたずら好きなお姉ちゃん
ユーザー milanis48663220
提出日時 2020-06-11 23:27:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,123 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 93,988 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-06-24 03:33:02
合計ジャッジ時間 5,016 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

map<int, ll> mp_min, mp_max;
int N;
int p[100000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> p[i];
    mp_min[p[0]] = 1;
    mp_max[p[0]] = 1;
    ll ans = 0;
    for(int i = 1; i < N; i++){
        auto ptr = mp_min.lower_bound(p[i]);
        ll sum = 0;
        vector<int> buf;
        for(auto iter = ptr; iter != mp_min.end(); iter++){
            sum += iter->second;
            buf.push_back(iter->first);
        }
        for(int j : buf) mp_min.erase(j);
        ans += sum;
        mp_min[p[i]] = sum+1;
        sum = 0;
        ptr = mp_max.lower_bound(p[i]);
        for(auto iter = mp_max.begin(); iter != ptr; iter++){
            sum += iter->second;
            buf.push_back(iter->first);
        }
        for(int j : buf) mp_max.erase(j);
        ans += sum;
        mp_max[p[i]] = sum+1;
    }
    cout << ans << endl;
}
0