#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int N=1e6+5;
int n,q;
ll ans,qs[N];
int arr[N],qst[N],dp[N];
set<int>st;
map<int,ll>mp;
priority_queue<pii,vector<pii>,greater<pii>>pq;
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> n >> q;
for(int i=1; i<=n; i++){
cin >> arr[i];
qs[i]=qs[i-1]+i;
pq.push({arr[i],i});
}
for(int i=1; i<=q; i++){
cin >> qst[i];
st.insert(qst[i]);
}
for(auto it=st.begin(); it!=st.end(); it++){
while(!pq.empty()&&pq.top().first<=*it){
int h=pq.top().first;
int idx=pq.top().second;
pq.pop();
dp[idx]=idx;
int l=idx,r=idx;
if(dp[idx-1]){
ans-=qs[(idx-1)-dp[idx-1]+1];
int tmp=dp[idx-1];
dp[dp[idx-1]]=idx;
dp[idx]=tmp;
l=tmp;
}
if(dp[idx+1]){
ans-=qs[dp[idx+1]-(idx+1)+1];
int tmp=dp[idx+1];
dp[dp[idx+1]]=dp[idx];
dp[dp[idx]]=tmp;
r=dp[l];
}
ans+=qs[r-l+1];
}
mp[*it]=ans;
}
for(int i=1; i<=q; i++){
cout << mp[qst[i]] << '\n';
}
return 0;
}
Compilation message
pilot.cpp: In function 'int main()':
pilot.cpp:28:17: warning: unused variable 'h' [-Wunused-variable]
28 | int h=pq.top().first;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4660 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
10964 KB |
Output is correct |
2 |
Correct |
20 ms |
10968 KB |
Output is correct |
3 |
Correct |
19 ms |
8848 KB |
Output is correct |
4 |
Correct |
18 ms |
8920 KB |
Output is correct |
5 |
Correct |
19 ms |
8792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
17156 KB |
Output is correct |
2 |
Correct |
83 ms |
19400 KB |
Output is correct |
3 |
Correct |
79 ms |
19448 KB |
Output is correct |
4 |
Correct |
79 ms |
21600 KB |
Output is correct |
5 |
Correct |
76 ms |
19172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
19632 KB |
Output is correct |
2 |
Correct |
80 ms |
19804 KB |
Output is correct |
3 |
Correct |
81 ms |
20004 KB |
Output is correct |
4 |
Correct |
80 ms |
19772 KB |
Output is correct |
5 |
Correct |
88 ms |
20428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
20 ms |
10964 KB |
Output is correct |
12 |
Correct |
20 ms |
10968 KB |
Output is correct |
13 |
Correct |
19 ms |
8848 KB |
Output is correct |
14 |
Correct |
18 ms |
8920 KB |
Output is correct |
15 |
Correct |
19 ms |
8792 KB |
Output is correct |
16 |
Correct |
16 ms |
8916 KB |
Output is correct |
17 |
Correct |
14 ms |
10968 KB |
Output is correct |
18 |
Correct |
11 ms |
11124 KB |
Output is correct |
19 |
Correct |
10 ms |
8664 KB |
Output is correct |
20 |
Correct |
17 ms |
10964 KB |
Output is correct |
21 |
Correct |
18 ms |
8664 KB |
Output is correct |
22 |
Correct |
14 ms |
8784 KB |
Output is correct |
23 |
Correct |
12 ms |
10968 KB |
Output is correct |
24 |
Correct |
11 ms |
8784 KB |
Output is correct |
25 |
Correct |
16 ms |
10968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4660 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
20 ms |
10964 KB |
Output is correct |
27 |
Correct |
20 ms |
10968 KB |
Output is correct |
28 |
Correct |
19 ms |
8848 KB |
Output is correct |
29 |
Correct |
18 ms |
8920 KB |
Output is correct |
30 |
Correct |
19 ms |
8792 KB |
Output is correct |
31 |
Correct |
86 ms |
17156 KB |
Output is correct |
32 |
Correct |
83 ms |
19400 KB |
Output is correct |
33 |
Correct |
79 ms |
19448 KB |
Output is correct |
34 |
Correct |
79 ms |
21600 KB |
Output is correct |
35 |
Correct |
76 ms |
19172 KB |
Output is correct |
36 |
Correct |
78 ms |
19632 KB |
Output is correct |
37 |
Correct |
80 ms |
19804 KB |
Output is correct |
38 |
Correct |
81 ms |
20004 KB |
Output is correct |
39 |
Correct |
80 ms |
19772 KB |
Output is correct |
40 |
Correct |
88 ms |
20428 KB |
Output is correct |
41 |
Correct |
16 ms |
8916 KB |
Output is correct |
42 |
Correct |
14 ms |
10968 KB |
Output is correct |
43 |
Correct |
11 ms |
11124 KB |
Output is correct |
44 |
Correct |
10 ms |
8664 KB |
Output is correct |
45 |
Correct |
17 ms |
10964 KB |
Output is correct |
46 |
Correct |
18 ms |
8664 KB |
Output is correct |
47 |
Correct |
14 ms |
8784 KB |
Output is correct |
48 |
Correct |
12 ms |
10968 KB |
Output is correct |
49 |
Correct |
11 ms |
8784 KB |
Output is correct |
50 |
Correct |
16 ms |
10968 KB |
Output is correct |
51 |
Correct |
86 ms |
23132 KB |
Output is correct |
52 |
Correct |
89 ms |
21704 KB |
Output is correct |
53 |
Correct |
86 ms |
22844 KB |
Output is correct |
54 |
Correct |
92 ms |
21676 KB |
Output is correct |
55 |
Correct |
84 ms |
22704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4660 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
20 ms |
10964 KB |
Output is correct |
27 |
Correct |
20 ms |
10968 KB |
Output is correct |
28 |
Correct |
19 ms |
8848 KB |
Output is correct |
29 |
Correct |
18 ms |
8920 KB |
Output is correct |
30 |
Correct |
19 ms |
8792 KB |
Output is correct |
31 |
Correct |
86 ms |
17156 KB |
Output is correct |
32 |
Correct |
83 ms |
19400 KB |
Output is correct |
33 |
Correct |
79 ms |
19448 KB |
Output is correct |
34 |
Correct |
79 ms |
21600 KB |
Output is correct |
35 |
Correct |
76 ms |
19172 KB |
Output is correct |
36 |
Correct |
78 ms |
19632 KB |
Output is correct |
37 |
Correct |
80 ms |
19804 KB |
Output is correct |
38 |
Correct |
81 ms |
20004 KB |
Output is correct |
39 |
Correct |
80 ms |
19772 KB |
Output is correct |
40 |
Correct |
88 ms |
20428 KB |
Output is correct |
41 |
Correct |
16 ms |
8916 KB |
Output is correct |
42 |
Correct |
14 ms |
10968 KB |
Output is correct |
43 |
Correct |
11 ms |
11124 KB |
Output is correct |
44 |
Correct |
10 ms |
8664 KB |
Output is correct |
45 |
Correct |
17 ms |
10964 KB |
Output is correct |
46 |
Correct |
18 ms |
8664 KB |
Output is correct |
47 |
Correct |
14 ms |
8784 KB |
Output is correct |
48 |
Correct |
12 ms |
10968 KB |
Output is correct |
49 |
Correct |
11 ms |
8784 KB |
Output is correct |
50 |
Correct |
16 ms |
10968 KB |
Output is correct |
51 |
Correct |
86 ms |
23132 KB |
Output is correct |
52 |
Correct |
89 ms |
21704 KB |
Output is correct |
53 |
Correct |
86 ms |
22844 KB |
Output is correct |
54 |
Correct |
92 ms |
21676 KB |
Output is correct |
55 |
Correct |
84 ms |
22704 KB |
Output is correct |
56 |
Execution timed out |
1070 ms |
106824 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |