#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define tc ll test;cin >> test;while(test--)
#define vi vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define INF 1e18
#define MOD 1000000007
#define ff first
#define ss second
#define in >>
#define out <<
#define space << " " <<
#define spacef << " "
#define fo(i,a,b) for(ll i = a; i <= b; i++)
#define rfo(i,a,b) for(ll i = a; i >= b; i--)
#define nextline out "\n"
#define print(x) for(auto i : x ) cout out i spacef
#define mmax(x,i) x = max(x,i)
#define mmin(x,i) x = min(x,i)
#define N 1000005
vi parent(N);
vi ssize(N);
void make_set(ll n){
fo(i,1,n){
parent[i] = i;
ssize[i] = 1;
}
}
ll find(ll x){
if(x == parent[x]) return x;
return parent[x] = find(parent[x]);
}
ll cnt = 0;
void add_edge(ll a , ll b){
a = find(a);
b = find(b);
if(a == b) return;
parent[b] = a;
cnt += ssize[a]*ssize[b];
ssize[a] += ssize[b];
}
int main() {
fast;
ll n,q;
cin in n in q;
vi h(n+5);
vector<pll> height(n+5);
fo(i,1,n){
cin in h[i];
height[i].first = h[i];
height[i].second = i;
}
sort(height.begin()+1,height.begin()+n+1);
make_set(n);
vi ans(N,-INF);
ans[0] = 0;
fo(i,1,n){
cnt++;
ll hi = height[i].first;
ll index = height[i].second;
if(index > 1 && h[index-1] <= hi){
add_edge(index,index-1);
}
if(index < n && h[index+1] <= hi){
add_edge(index,index+1);
}
ans[hi] = cnt;
}
fo(i,1,N) if(ans[i] == -INF) ans[i] = ans[i-1];
while(q--){
ll x;
cin in x;
cout out ans[x] nextline;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23804 KB |
Output is correct |
2 |
Correct |
11 ms |
23780 KB |
Output is correct |
3 |
Correct |
11 ms |
23772 KB |
Output is correct |
4 |
Correct |
11 ms |
23816 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
13 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23692 KB |
Output is correct |
9 |
Correct |
14 ms |
23756 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23804 KB |
Output is correct |
2 |
Correct |
11 ms |
23780 KB |
Output is correct |
3 |
Correct |
11 ms |
23772 KB |
Output is correct |
4 |
Correct |
11 ms |
23816 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
13 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23692 KB |
Output is correct |
9 |
Correct |
14 ms |
23756 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
11 ms |
23756 KB |
Output is correct |
12 |
Correct |
12 ms |
23792 KB |
Output is correct |
13 |
Correct |
11 ms |
23756 KB |
Output is correct |
14 |
Correct |
11 ms |
23716 KB |
Output is correct |
15 |
Correct |
12 ms |
23720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23804 KB |
Output is correct |
2 |
Correct |
11 ms |
23780 KB |
Output is correct |
3 |
Correct |
11 ms |
23772 KB |
Output is correct |
4 |
Correct |
11 ms |
23816 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
13 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23692 KB |
Output is correct |
9 |
Correct |
14 ms |
23756 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
11 ms |
23756 KB |
Output is correct |
12 |
Correct |
12 ms |
23792 KB |
Output is correct |
13 |
Correct |
11 ms |
23756 KB |
Output is correct |
14 |
Correct |
11 ms |
23716 KB |
Output is correct |
15 |
Correct |
12 ms |
23720 KB |
Output is correct |
16 |
Correct |
11 ms |
23756 KB |
Output is correct |
17 |
Correct |
13 ms |
23816 KB |
Output is correct |
18 |
Correct |
12 ms |
23792 KB |
Output is correct |
19 |
Correct |
12 ms |
23724 KB |
Output is correct |
20 |
Correct |
12 ms |
23756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23804 KB |
Output is correct |
2 |
Correct |
11 ms |
23780 KB |
Output is correct |
3 |
Correct |
11 ms |
23772 KB |
Output is correct |
4 |
Correct |
11 ms |
23816 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
13 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23692 KB |
Output is correct |
9 |
Correct |
14 ms |
23756 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
11 ms |
23756 KB |
Output is correct |
12 |
Correct |
12 ms |
23792 KB |
Output is correct |
13 |
Correct |
11 ms |
23756 KB |
Output is correct |
14 |
Correct |
11 ms |
23716 KB |
Output is correct |
15 |
Correct |
12 ms |
23720 KB |
Output is correct |
16 |
Correct |
11 ms |
23756 KB |
Output is correct |
17 |
Correct |
13 ms |
23816 KB |
Output is correct |
18 |
Correct |
12 ms |
23792 KB |
Output is correct |
19 |
Correct |
12 ms |
23724 KB |
Output is correct |
20 |
Correct |
12 ms |
23756 KB |
Output is correct |
21 |
Correct |
17 ms |
23756 KB |
Output is correct |
22 |
Correct |
13 ms |
23804 KB |
Output is correct |
23 |
Correct |
15 ms |
23752 KB |
Output is correct |
24 |
Correct |
15 ms |
23756 KB |
Output is correct |
25 |
Correct |
16 ms |
23856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
26588 KB |
Output is correct |
2 |
Correct |
35 ms |
26748 KB |
Output is correct |
3 |
Correct |
31 ms |
26484 KB |
Output is correct |
4 |
Correct |
29 ms |
26444 KB |
Output is correct |
5 |
Correct |
30 ms |
26508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
27984 KB |
Output is correct |
2 |
Correct |
42 ms |
28124 KB |
Output is correct |
3 |
Correct |
39 ms |
27972 KB |
Output is correct |
4 |
Correct |
42 ms |
28096 KB |
Output is correct |
5 |
Correct |
39 ms |
27972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
28252 KB |
Output is correct |
2 |
Correct |
42 ms |
28152 KB |
Output is correct |
3 |
Correct |
40 ms |
28100 KB |
Output is correct |
4 |
Correct |
42 ms |
28300 KB |
Output is correct |
5 |
Correct |
47 ms |
28228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23804 KB |
Output is correct |
2 |
Correct |
11 ms |
23780 KB |
Output is correct |
3 |
Correct |
11 ms |
23772 KB |
Output is correct |
4 |
Correct |
11 ms |
23816 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
13 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23692 KB |
Output is correct |
9 |
Correct |
14 ms |
23756 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
33 ms |
26588 KB |
Output is correct |
12 |
Correct |
35 ms |
26748 KB |
Output is correct |
13 |
Correct |
31 ms |
26484 KB |
Output is correct |
14 |
Correct |
29 ms |
26444 KB |
Output is correct |
15 |
Correct |
30 ms |
26508 KB |
Output is correct |
16 |
Correct |
31 ms |
26436 KB |
Output is correct |
17 |
Correct |
31 ms |
26748 KB |
Output is correct |
18 |
Correct |
32 ms |
26792 KB |
Output is correct |
19 |
Correct |
31 ms |
26504 KB |
Output is correct |
20 |
Correct |
34 ms |
26708 KB |
Output is correct |
21 |
Correct |
38 ms |
26472 KB |
Output is correct |
22 |
Correct |
33 ms |
26580 KB |
Output is correct |
23 |
Correct |
32 ms |
26680 KB |
Output is correct |
24 |
Correct |
32 ms |
26556 KB |
Output is correct |
25 |
Correct |
31 ms |
26564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23804 KB |
Output is correct |
2 |
Correct |
11 ms |
23780 KB |
Output is correct |
3 |
Correct |
11 ms |
23772 KB |
Output is correct |
4 |
Correct |
11 ms |
23816 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
13 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23692 KB |
Output is correct |
9 |
Correct |
14 ms |
23756 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
11 ms |
23756 KB |
Output is correct |
12 |
Correct |
12 ms |
23792 KB |
Output is correct |
13 |
Correct |
11 ms |
23756 KB |
Output is correct |
14 |
Correct |
11 ms |
23716 KB |
Output is correct |
15 |
Correct |
12 ms |
23720 KB |
Output is correct |
16 |
Correct |
11 ms |
23756 KB |
Output is correct |
17 |
Correct |
13 ms |
23816 KB |
Output is correct |
18 |
Correct |
12 ms |
23792 KB |
Output is correct |
19 |
Correct |
12 ms |
23724 KB |
Output is correct |
20 |
Correct |
12 ms |
23756 KB |
Output is correct |
21 |
Correct |
17 ms |
23756 KB |
Output is correct |
22 |
Correct |
13 ms |
23804 KB |
Output is correct |
23 |
Correct |
15 ms |
23752 KB |
Output is correct |
24 |
Correct |
15 ms |
23756 KB |
Output is correct |
25 |
Correct |
16 ms |
23856 KB |
Output is correct |
26 |
Correct |
33 ms |
26588 KB |
Output is correct |
27 |
Correct |
35 ms |
26748 KB |
Output is correct |
28 |
Correct |
31 ms |
26484 KB |
Output is correct |
29 |
Correct |
29 ms |
26444 KB |
Output is correct |
30 |
Correct |
30 ms |
26508 KB |
Output is correct |
31 |
Correct |
50 ms |
27984 KB |
Output is correct |
32 |
Correct |
42 ms |
28124 KB |
Output is correct |
33 |
Correct |
39 ms |
27972 KB |
Output is correct |
34 |
Correct |
42 ms |
28096 KB |
Output is correct |
35 |
Correct |
39 ms |
27972 KB |
Output is correct |
36 |
Correct |
60 ms |
28252 KB |
Output is correct |
37 |
Correct |
42 ms |
28152 KB |
Output is correct |
38 |
Correct |
40 ms |
28100 KB |
Output is correct |
39 |
Correct |
42 ms |
28300 KB |
Output is correct |
40 |
Correct |
47 ms |
28228 KB |
Output is correct |
41 |
Correct |
31 ms |
26436 KB |
Output is correct |
42 |
Correct |
31 ms |
26748 KB |
Output is correct |
43 |
Correct |
32 ms |
26792 KB |
Output is correct |
44 |
Correct |
31 ms |
26504 KB |
Output is correct |
45 |
Correct |
34 ms |
26708 KB |
Output is correct |
46 |
Correct |
38 ms |
26472 KB |
Output is correct |
47 |
Correct |
33 ms |
26580 KB |
Output is correct |
48 |
Correct |
32 ms |
26680 KB |
Output is correct |
49 |
Correct |
32 ms |
26556 KB |
Output is correct |
50 |
Correct |
31 ms |
26564 KB |
Output is correct |
51 |
Correct |
69 ms |
28012 KB |
Output is correct |
52 |
Correct |
49 ms |
27916 KB |
Output is correct |
53 |
Correct |
48 ms |
27996 KB |
Output is correct |
54 |
Correct |
50 ms |
28032 KB |
Output is correct |
55 |
Correct |
67 ms |
28020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23804 KB |
Output is correct |
2 |
Correct |
11 ms |
23780 KB |
Output is correct |
3 |
Correct |
11 ms |
23772 KB |
Output is correct |
4 |
Correct |
11 ms |
23816 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
13 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23692 KB |
Output is correct |
9 |
Correct |
14 ms |
23756 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
11 ms |
23756 KB |
Output is correct |
12 |
Correct |
12 ms |
23792 KB |
Output is correct |
13 |
Correct |
11 ms |
23756 KB |
Output is correct |
14 |
Correct |
11 ms |
23716 KB |
Output is correct |
15 |
Correct |
12 ms |
23720 KB |
Output is correct |
16 |
Correct |
11 ms |
23756 KB |
Output is correct |
17 |
Correct |
13 ms |
23816 KB |
Output is correct |
18 |
Correct |
12 ms |
23792 KB |
Output is correct |
19 |
Correct |
12 ms |
23724 KB |
Output is correct |
20 |
Correct |
12 ms |
23756 KB |
Output is correct |
21 |
Correct |
17 ms |
23756 KB |
Output is correct |
22 |
Correct |
13 ms |
23804 KB |
Output is correct |
23 |
Correct |
15 ms |
23752 KB |
Output is correct |
24 |
Correct |
15 ms |
23756 KB |
Output is correct |
25 |
Correct |
16 ms |
23856 KB |
Output is correct |
26 |
Correct |
33 ms |
26588 KB |
Output is correct |
27 |
Correct |
35 ms |
26748 KB |
Output is correct |
28 |
Correct |
31 ms |
26484 KB |
Output is correct |
29 |
Correct |
29 ms |
26444 KB |
Output is correct |
30 |
Correct |
30 ms |
26508 KB |
Output is correct |
31 |
Correct |
50 ms |
27984 KB |
Output is correct |
32 |
Correct |
42 ms |
28124 KB |
Output is correct |
33 |
Correct |
39 ms |
27972 KB |
Output is correct |
34 |
Correct |
42 ms |
28096 KB |
Output is correct |
35 |
Correct |
39 ms |
27972 KB |
Output is correct |
36 |
Correct |
60 ms |
28252 KB |
Output is correct |
37 |
Correct |
42 ms |
28152 KB |
Output is correct |
38 |
Correct |
40 ms |
28100 KB |
Output is correct |
39 |
Correct |
42 ms |
28300 KB |
Output is correct |
40 |
Correct |
47 ms |
28228 KB |
Output is correct |
41 |
Correct |
31 ms |
26436 KB |
Output is correct |
42 |
Correct |
31 ms |
26748 KB |
Output is correct |
43 |
Correct |
32 ms |
26792 KB |
Output is correct |
44 |
Correct |
31 ms |
26504 KB |
Output is correct |
45 |
Correct |
34 ms |
26708 KB |
Output is correct |
46 |
Correct |
38 ms |
26472 KB |
Output is correct |
47 |
Correct |
33 ms |
26580 KB |
Output is correct |
48 |
Correct |
32 ms |
26680 KB |
Output is correct |
49 |
Correct |
32 ms |
26556 KB |
Output is correct |
50 |
Correct |
31 ms |
26564 KB |
Output is correct |
51 |
Correct |
69 ms |
28012 KB |
Output is correct |
52 |
Correct |
49 ms |
27916 KB |
Output is correct |
53 |
Correct |
48 ms |
27996 KB |
Output is correct |
54 |
Correct |
50 ms |
28032 KB |
Output is correct |
55 |
Correct |
67 ms |
28020 KB |
Output is correct |
56 |
Correct |
507 ms |
66476 KB |
Output is correct |
57 |
Correct |
497 ms |
67012 KB |
Output is correct |
58 |
Correct |
521 ms |
64244 KB |
Output is correct |
59 |
Correct |
467 ms |
65272 KB |
Output is correct |
60 |
Correct |
511 ms |
67784 KB |
Output is correct |