#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int n,m;
pair<int,int> a[N],q[N];
set<pair<int,int> > s;
long long ans[N],now;
void add(int x)
{
auto it = s.lower_bound({x,INT_MAX});
int l = 0,r = 0,ll = x,rr = x;
if(it!=s.begin()){ it--; if(it->second==x-1) l = it->second-it->first+1,ll = it->first,it = s.erase(it); else it++; }
if(it!=s.end()){ if(it->first==x+1) r = it->second-it->first+1,rr = it->second,s.erase(it); }
now+=(long long)((l+1)*(r+1));
s.insert({ll,rr});
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i++) cin >> a[i].first,a[i].second = i;
for(int i = 1;i <= m;i++) cin >> q[i].first,q[i].second = i;
sort(q+1,q+m+1),sort(a+1,a+n+1);
int x = 1,y = 1;
while(y<=m)
{
while(x<=n and a[x].first<=q[y].first) add(a[x].second),x++;
ans[q[y].second] = now,y++;
}
for(int i = 1;i <= m;i++) cout << ans[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
2296 KB |
Output is correct |
2 |
Correct |
66 ms |
2640 KB |
Output is correct |
3 |
Correct |
61 ms |
2424 KB |
Output is correct |
4 |
Correct |
61 ms |
2424 KB |
Output is correct |
5 |
Correct |
60 ms |
2424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
3576 KB |
Output is correct |
2 |
Correct |
57 ms |
3960 KB |
Output is correct |
3 |
Correct |
50 ms |
3832 KB |
Output is correct |
4 |
Correct |
58 ms |
3960 KB |
Output is correct |
5 |
Correct |
55 ms |
3784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
3576 KB |
Output is correct |
2 |
Correct |
57 ms |
3832 KB |
Output is correct |
3 |
Correct |
60 ms |
3832 KB |
Output is correct |
4 |
Correct |
58 ms |
3832 KB |
Output is correct |
5 |
Correct |
56 ms |
3960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
64 ms |
2296 KB |
Output is correct |
12 |
Correct |
66 ms |
2640 KB |
Output is correct |
13 |
Correct |
61 ms |
2424 KB |
Output is correct |
14 |
Correct |
61 ms |
2424 KB |
Output is correct |
15 |
Correct |
60 ms |
2424 KB |
Output is correct |
16 |
Correct |
51 ms |
2552 KB |
Output is correct |
17 |
Correct |
39 ms |
2424 KB |
Output is correct |
18 |
Correct |
30 ms |
1784 KB |
Output is correct |
19 |
Correct |
25 ms |
1664 KB |
Output is correct |
20 |
Correct |
42 ms |
2424 KB |
Output is correct |
21 |
Correct |
58 ms |
2424 KB |
Output is correct |
22 |
Correct |
43 ms |
2424 KB |
Output is correct |
23 |
Correct |
38 ms |
2424 KB |
Output is correct |
24 |
Correct |
30 ms |
2048 KB |
Output is correct |
25 |
Correct |
44 ms |
2424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
64 ms |
2296 KB |
Output is correct |
27 |
Correct |
66 ms |
2640 KB |
Output is correct |
28 |
Correct |
61 ms |
2424 KB |
Output is correct |
29 |
Correct |
61 ms |
2424 KB |
Output is correct |
30 |
Correct |
60 ms |
2424 KB |
Output is correct |
31 |
Correct |
57 ms |
3576 KB |
Output is correct |
32 |
Correct |
57 ms |
3960 KB |
Output is correct |
33 |
Correct |
50 ms |
3832 KB |
Output is correct |
34 |
Correct |
58 ms |
3960 KB |
Output is correct |
35 |
Correct |
55 ms |
3784 KB |
Output is correct |
36 |
Correct |
55 ms |
3576 KB |
Output is correct |
37 |
Correct |
57 ms |
3832 KB |
Output is correct |
38 |
Correct |
60 ms |
3832 KB |
Output is correct |
39 |
Correct |
58 ms |
3832 KB |
Output is correct |
40 |
Correct |
56 ms |
3960 KB |
Output is correct |
41 |
Correct |
51 ms |
2552 KB |
Output is correct |
42 |
Correct |
39 ms |
2424 KB |
Output is correct |
43 |
Correct |
30 ms |
1784 KB |
Output is correct |
44 |
Correct |
25 ms |
1664 KB |
Output is correct |
45 |
Correct |
42 ms |
2424 KB |
Output is correct |
46 |
Correct |
58 ms |
2424 KB |
Output is correct |
47 |
Correct |
43 ms |
2424 KB |
Output is correct |
48 |
Correct |
38 ms |
2424 KB |
Output is correct |
49 |
Correct |
30 ms |
2048 KB |
Output is correct |
50 |
Correct |
44 ms |
2424 KB |
Output is correct |
51 |
Correct |
94 ms |
4856 KB |
Output is correct |
52 |
Correct |
96 ms |
4600 KB |
Output is correct |
53 |
Correct |
96 ms |
4856 KB |
Output is correct |
54 |
Correct |
89 ms |
4600 KB |
Output is correct |
55 |
Incorrect |
98 ms |
4744 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
64 ms |
2296 KB |
Output is correct |
27 |
Correct |
66 ms |
2640 KB |
Output is correct |
28 |
Correct |
61 ms |
2424 KB |
Output is correct |
29 |
Correct |
61 ms |
2424 KB |
Output is correct |
30 |
Correct |
60 ms |
2424 KB |
Output is correct |
31 |
Correct |
57 ms |
3576 KB |
Output is correct |
32 |
Correct |
57 ms |
3960 KB |
Output is correct |
33 |
Correct |
50 ms |
3832 KB |
Output is correct |
34 |
Correct |
58 ms |
3960 KB |
Output is correct |
35 |
Correct |
55 ms |
3784 KB |
Output is correct |
36 |
Correct |
55 ms |
3576 KB |
Output is correct |
37 |
Correct |
57 ms |
3832 KB |
Output is correct |
38 |
Correct |
60 ms |
3832 KB |
Output is correct |
39 |
Correct |
58 ms |
3832 KB |
Output is correct |
40 |
Correct |
56 ms |
3960 KB |
Output is correct |
41 |
Correct |
51 ms |
2552 KB |
Output is correct |
42 |
Correct |
39 ms |
2424 KB |
Output is correct |
43 |
Correct |
30 ms |
1784 KB |
Output is correct |
44 |
Correct |
25 ms |
1664 KB |
Output is correct |
45 |
Correct |
42 ms |
2424 KB |
Output is correct |
46 |
Correct |
58 ms |
2424 KB |
Output is correct |
47 |
Correct |
43 ms |
2424 KB |
Output is correct |
48 |
Correct |
38 ms |
2424 KB |
Output is correct |
49 |
Correct |
30 ms |
2048 KB |
Output is correct |
50 |
Correct |
44 ms |
2424 KB |
Output is correct |
51 |
Correct |
94 ms |
4856 KB |
Output is correct |
52 |
Correct |
96 ms |
4600 KB |
Output is correct |
53 |
Correct |
96 ms |
4856 KB |
Output is correct |
54 |
Correct |
89 ms |
4600 KB |
Output is correct |
55 |
Incorrect |
98 ms |
4744 KB |
Output isn't correct |