#include<bits/stdc++.h>
using namespace std;
int a[1000010];
int l[1000010];
int r[1000010];
int dp[100010];
priority_queue<pair<int,int>> pq;
int main(){
int n,q;
cin>>n>>q;
l[0]=-1;
r[0]=1;
l[n+1]=n;
r[n+1]=n+2;
int maxi=0;
for(int i=1;i<=n;i++){
cin>>a[i];
l[i]=i-1;
r[i]=i+1;
pq.push({-a[i],-i});
if(a[i]>maxi)
maxi=a[i];
}
int sumi=0;
while(pq.empty()==0){
int x=pq.top().first;
int y=pq.top().second;
pq.pop();
int g=(r[-y]-r[-y-1])*(l[-y+1]-l[-y]);
sumi+=g;
l[r[-y-1]]=l[-y+1];
r[l[-y+1]]=r[-y-1];
dp[-x]=sumi;
}
for(int i=1;i<=maxi;i++){
if(dp[i]==0)
dp[i]=dp[i-1];
}
for(int i=0;i<q;i++){
int ans;
cin>>ans;
ans=min(ans,maxi);
cout<<dp[ans]<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2140 KB |
Output is correct |
3 |
Correct |
2 ms |
3776 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
3932 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2140 KB |
Output is correct |
3 |
Correct |
2 ms |
3776 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
3932 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2140 KB |
Output is correct |
3 |
Correct |
2 ms |
3776 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
3932 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2140 KB |
Output is correct |
3 |
Correct |
2 ms |
3776 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
3932 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
3252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
135 ms |
4628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
140 ms |
8132 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2140 KB |
Output is correct |
3 |
Correct |
2 ms |
3776 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
3932 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2140 KB |
Output is correct |
3 |
Correct |
2 ms |
3776 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
3932 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2140 KB |
Output is correct |
3 |
Correct |
2 ms |
3776 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
3932 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |