제출 #1123786

#제출 시각아이디문제언어결과실행 시간메모리
1123786tuannmPilot (NOI19_pilot)C++20
100 / 100
507 ms70412 KiB
#include<bits/stdc++.h>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 1e6 + 1;
const string NAME = "";
int n, q, a[N], L[N], R[N];
long long ans[N];
vector<int> pos[N];

void inp(){
    cin >> n >> q;

    for(int i = 1; i <= n; ++i)
        cin >> a[i];
}

void solve(){
    stack<int> stk;

    for(int i = 1; i <= n; ++i){
        while(!stk.empty() && a[stk.top()] <= a[i])
            stk.pop();

        L[i] = (stk.empty() ? 1 : stk.top() + 1);
        stk.push(i);

        pos[a[i]].pb(i);
    }

    while(!stk.empty())
        stk.pop();

    for(int i = n; i > 0; --i){
        while(!stk.empty() && a[stk.top()] < a[i])
            stk.pop();

        R[i] = (stk.empty() ? n : stk.top() - 1);
        stk.push(i);
    }

    for(int i = 1; i < N; ++i){
        ans[i] = ans[i - 1];
        for(int j : pos[i])
            ans[i] += 1LL * (j - L[j] + 1) * (R[j] - j + 1);
    }

    while(q--){
        int y;
        cin >> y;
        cout << ans[y] << "\n";
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen((NAME + ".inp").c_str(), "r")){
        freopen((NAME + ".inp").c_str(), "r", stdin);
        freopen((NAME + ".out").c_str(), "w", stdout);
    }

    inp();
    solve();
}

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

pilot.cpp: In function 'int main()':
pilot.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen((NAME + ".out").c_str(), "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...