Submission #330315

#TimeUsernameProblemLanguageResultExecution timeMemory
330315jungsnowPilot (NOI19_pilot)C++14
100 / 100
468 ms40684 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 1000100; int N, Q, H[maxn]; int L[maxn], R[maxn]; ll Ans[maxn]; int main() { // freopen("pilot.inp", "r", stdin); // freopen("pilot.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(nullptr); cin >> N >> Q; stack<int> st; for (int i = 1; i <= N; ++i) { cin >> H[i]; while (!st.empty() && H[st.top()] <= H[i]) st.pop(); if (st.empty()) L[i] = 1; else L[i] = st.top() + 1; st.push(i); } while (!st.empty()) st.pop(); for (int i = N; i >= 1; --i) { while (!st.empty() && H[st.top()] < H[i]) st.pop(); if (st.empty()) R[i] = N; else R[i] = st.top() - 1; st.push(i); Ans[H[i]] += 1ll * (R[i] - i + 1) * (i - L[i] + 1); } for (int i = 1; i <= 1000000; ++i) Ans[i] += Ans[i - 1]; for (int i = 1; i <= Q; ++i) { int Y; cin >> Y; cout << Ans[Y] << '\n'; } }
#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...