This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll D[1010101];
int A[1010101], S[1010101];
int n;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int q, i, j, t;
cin >> n >> q;
for(i = 1, j = 0, A[0] = 1e6 + 1; i <= n; i ++){
cin >> A[i];
for(; j && A[S[j]] < A[i]; j --){
D[A[S[j]]] += (ll)(i - S[j]) * (S[j] - S[j - 1]);
}
S[++ j] = i;
}
for(; j; j --){
D[A[S[j]]] += (ll)(i - S[j]) * (S[j] - S[j - 1]);
}
for(i = 1; i <= 1e6; i ++){
D[i] += D[i - 1];
}
for(; q --; ){
cin >> t;
cout << D[t] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |