#include <bits/stdc++.h>
#define int long long
using namespace std;
const int md=1e9+7;
int32_t main(){
cin.tie(NULL)->sync_with_stdio(false);
int n,q; cin >> n >> q;
vector<int> he(n+1);
vector<pair<int,int>> h(n+1),y(q+1);
vector<int> pri(q+1);
int ans=n*(n+1)/2;
for(int i=1 ; i<=n ; i++) cin >> h[i].first,he[i]=h[i].first,h[i].second=i;
for(int i=1 ; i<=q ; i++) cin >> y[i].first,y[i].second=i;
sort(h.begin(),h.end());
sort(he.begin(),he.end());
sort(y.begin(),y.end());
reverse(y.begin()+1,y.end());
set<int> s;
s.insert(0);
s.insert(n+1);
int id=n;
for(int t=1 ; t<=q ; t++){
int idx=upper_bound(he.begin(),he.end(),y[t].first)-he.begin();
//cout << "idx== " << idx << " id== " << id << '\n';
for(int i=idx ; i<=id ; i++){
s.insert(h[i].second);
auto itr=s.lower_bound(h[i].second);
int now=*itr;
//cout << "itr== " << now << '\n';
itr--;
int l=*itr;
//cout << "itrl== " << l << '\n';
itr++;
itr++;
auto r=*itr;
//cout << "itrr== " << r << '\n';
ans-=(now-l-1)*(r-now-1);
ans-=r-l-1;
//cout << "ans== " << ans << '\n';
}
id=idx-1;
pri[y[t].second]=ans;
}
for(int i=1 ; i<=q ; i++){
cout << pri[i] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
452 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
452 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
420 KB |
Output is correct |
13 |
Correct |
0 ms |
452 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
452 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
420 KB |
Output is correct |
13 |
Correct |
0 ms |
452 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
452 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
420 KB |
Output is correct |
13 |
Correct |
0 ms |
452 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3164 KB |
Output is correct |
2 |
Correct |
19 ms |
3420 KB |
Output is correct |
3 |
Correct |
17 ms |
3028 KB |
Output is correct |
4 |
Correct |
17 ms |
3164 KB |
Output is correct |
5 |
Correct |
18 ms |
3160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
11088 KB |
Output is correct |
2 |
Correct |
47 ms |
11348 KB |
Output is correct |
3 |
Correct |
42 ms |
11088 KB |
Output is correct |
4 |
Correct |
43 ms |
11604 KB |
Output is correct |
5 |
Correct |
41 ms |
11092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
11340 KB |
Output is correct |
2 |
Correct |
46 ms |
11364 KB |
Output is correct |
3 |
Correct |
46 ms |
11348 KB |
Output is correct |
4 |
Correct |
44 ms |
11812 KB |
Output is correct |
5 |
Correct |
45 ms |
11648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
452 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
18 ms |
3164 KB |
Output is correct |
12 |
Correct |
19 ms |
3420 KB |
Output is correct |
13 |
Correct |
17 ms |
3028 KB |
Output is correct |
14 |
Correct |
17 ms |
3164 KB |
Output is correct |
15 |
Correct |
18 ms |
3160 KB |
Output is correct |
16 |
Correct |
24 ms |
4444 KB |
Output is correct |
17 |
Correct |
41 ms |
6228 KB |
Output is correct |
18 |
Correct |
45 ms |
7552 KB |
Output is correct |
19 |
Correct |
41 ms |
6992 KB |
Output is correct |
20 |
Correct |
31 ms |
5456 KB |
Output is correct |
21 |
Correct |
17 ms |
2908 KB |
Output is correct |
22 |
Correct |
29 ms |
5200 KB |
Output is correct |
23 |
Correct |
41 ms |
6696 KB |
Output is correct |
24 |
Correct |
38 ms |
6484 KB |
Output is correct |
25 |
Correct |
36 ms |
5460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
452 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
420 KB |
Output is correct |
13 |
Correct |
0 ms |
452 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
18 ms |
3164 KB |
Output is correct |
27 |
Correct |
19 ms |
3420 KB |
Output is correct |
28 |
Correct |
17 ms |
3028 KB |
Output is correct |
29 |
Correct |
17 ms |
3164 KB |
Output is correct |
30 |
Correct |
18 ms |
3160 KB |
Output is correct |
31 |
Correct |
42 ms |
11088 KB |
Output is correct |
32 |
Correct |
47 ms |
11348 KB |
Output is correct |
33 |
Correct |
42 ms |
11088 KB |
Output is correct |
34 |
Correct |
43 ms |
11604 KB |
Output is correct |
35 |
Correct |
41 ms |
11092 KB |
Output is correct |
36 |
Correct |
44 ms |
11340 KB |
Output is correct |
37 |
Correct |
46 ms |
11364 KB |
Output is correct |
38 |
Correct |
46 ms |
11348 KB |
Output is correct |
39 |
Correct |
44 ms |
11812 KB |
Output is correct |
40 |
Correct |
45 ms |
11648 KB |
Output is correct |
41 |
Correct |
24 ms |
4444 KB |
Output is correct |
42 |
Correct |
41 ms |
6228 KB |
Output is correct |
43 |
Correct |
45 ms |
7552 KB |
Output is correct |
44 |
Correct |
41 ms |
6992 KB |
Output is correct |
45 |
Correct |
31 ms |
5456 KB |
Output is correct |
46 |
Correct |
17 ms |
2908 KB |
Output is correct |
47 |
Correct |
29 ms |
5200 KB |
Output is correct |
48 |
Correct |
41 ms |
6696 KB |
Output is correct |
49 |
Correct |
38 ms |
6484 KB |
Output is correct |
50 |
Correct |
36 ms |
5460 KB |
Output is correct |
51 |
Correct |
68 ms |
11380 KB |
Output is correct |
52 |
Correct |
68 ms |
11172 KB |
Output is correct |
53 |
Correct |
68 ms |
11504 KB |
Output is correct |
54 |
Correct |
72 ms |
11208 KB |
Output is correct |
55 |
Correct |
72 ms |
11476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
452 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
420 KB |
Output is correct |
13 |
Correct |
0 ms |
452 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
18 ms |
3164 KB |
Output is correct |
27 |
Correct |
19 ms |
3420 KB |
Output is correct |
28 |
Correct |
17 ms |
3028 KB |
Output is correct |
29 |
Correct |
17 ms |
3164 KB |
Output is correct |
30 |
Correct |
18 ms |
3160 KB |
Output is correct |
31 |
Correct |
42 ms |
11088 KB |
Output is correct |
32 |
Correct |
47 ms |
11348 KB |
Output is correct |
33 |
Correct |
42 ms |
11088 KB |
Output is correct |
34 |
Correct |
43 ms |
11604 KB |
Output is correct |
35 |
Correct |
41 ms |
11092 KB |
Output is correct |
36 |
Correct |
44 ms |
11340 KB |
Output is correct |
37 |
Correct |
46 ms |
11364 KB |
Output is correct |
38 |
Correct |
46 ms |
11348 KB |
Output is correct |
39 |
Correct |
44 ms |
11812 KB |
Output is correct |
40 |
Correct |
45 ms |
11648 KB |
Output is correct |
41 |
Correct |
24 ms |
4444 KB |
Output is correct |
42 |
Correct |
41 ms |
6228 KB |
Output is correct |
43 |
Correct |
45 ms |
7552 KB |
Output is correct |
44 |
Correct |
41 ms |
6992 KB |
Output is correct |
45 |
Correct |
31 ms |
5456 KB |
Output is correct |
46 |
Correct |
17 ms |
2908 KB |
Output is correct |
47 |
Correct |
29 ms |
5200 KB |
Output is correct |
48 |
Correct |
41 ms |
6696 KB |
Output is correct |
49 |
Correct |
38 ms |
6484 KB |
Output is correct |
50 |
Correct |
36 ms |
5460 KB |
Output is correct |
51 |
Correct |
68 ms |
11380 KB |
Output is correct |
52 |
Correct |
68 ms |
11172 KB |
Output is correct |
53 |
Correct |
68 ms |
11504 KB |
Output is correct |
54 |
Correct |
72 ms |
11208 KB |
Output is correct |
55 |
Correct |
72 ms |
11476 KB |
Output is correct |
56 |
Execution timed out |
1006 ms |
110416 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |