제출 #329319

#제출 시각아이디문제언어결과실행 시간메모리
329319BeanZPilot (NOI19_pilot)C++14
100 / 100
464 ms52332 KiB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
const int lg = 60;
const int mod = 998244353;
const long long oo = 1e18;
const int lim = 1e6;
ll cnt[N], h[N], r[N], l[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("A.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> h[i];
    vector<ll> st;
    for (int i = 1; i <= n; i++){
        while (st.size()){
            if (h[st.back()] <= h[i]){
                st.pop_back();
            } else break;
        }
        if (st.size()) l[i] = st.back() + 1;
        else l[i] = 1;
        st.push_back(i);
    }
    st.clear();
    for (int i = n; i >= 1; i--){
        while (st.size()){
            if (h[st.back()] < h[i]){
                st.pop_back();
            } else break;
        }
        if (st.size()) r[i] = st.back() - 1;
        else r[i] = n;
        st.push_back(i);
    }
    for (int i = 1; i <= n; i++){
        cnt[h[i]] += (i - l[i] + 1) * (r[i] - i + 1);
    }
    for (int i = 2; i <= lim; i++) cnt[i] += cnt[i - 1];
    while (q--){
        ll x;
        cin >> x;
        cout << cnt[x] << endl;
    }
}
/*
*/

컴파일 시 표준 에러 (stderr) 메시지

pilot.cpp: In function 'int main()':
pilot.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   17 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...