d028. 例題 P-3-4. 最接近的高人 (APCS201902, subtask) - TCFSH CIRC Judge

本文最後更新於:2024年1月12日 下午

d028. 例題 P-3-4. 最接近的高人 (APCS201902, subtask) - TCFSH CIRC Judge

AP325-d028.cpp

// Author : ysh
// 03/09/2022 Wed 10:38:11.99
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    //freopen("1.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;cin>>n;
    vector<pair<int,int>>f;
    f.push_back(make_pair(INT_MAX,0));
    int tmp,ans = 0;
    for(int i = 1;i<=n;i++) {
        cin>>tmp;
        while(f.back().first <= tmp) f.pop_back();
        ans += i - f.back().second;
        f.push_back(make_pair(tmp,i));
    }
    cout<<ans;
    return 0;
}

d028. 例題 P-3-4. 最接近的高人 (APCS201902, subtask) - TCFSH CIRC Judge
http://mysh212.github.io/algosolution/AP325-d028.cpp/
作者
ysh
發布於
2022年3月9日
更新於
2024年1月12日
許可協議