#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define ull unsigned long long
#define ld long double
#define pii pair<int, int>
#define nl '\n'
#define tb '\t'
#define sp ' '
using namespace std;
const int MX=1000007, MOD=1e9+7, BLOCK=330, INF=1e9+7;
const ld ERR=1e-7, pi=3.14159265358979323846;
int N, Q, Y, H[MX];
ll tot=0, ans[MX];
pii A[MX];
ll calc(int x){
return x*(1ll+x)/2ll;
}
struct dsu{
int par[MX], sz[MX];
dsu(){
for(int i=0; i<MX; i++){
par[i]=i;
sz[i]=1;
}
}
int f(int u){
if(par[u]!=u)
par[u]=f(par[u]);
return par[u];
}
void join(int u, int v){
u=f(u);
v=f(v);
if(u==v)
return;
tot-=calc(sz[u])+calc(sz[v]);
par[u]=v;
sz[v]+=sz[u];
tot+=calc(sz[v]);
}
}DSU;
int main(){
fastio;
cin >> N >> Q;
for(int i=0; i<N; i++){
cin >> H[i];
A[i]={H[i], i};
}
sort(A, A+N);
for(int i=0; i<N; i++){
tot++;
int h=A[i].fi, idx=A[i].se;
if(idx && H[idx-1]<=h)
DSU.join(idx-1, idx);
if(idx+1<N && H[idx+1]<=h)
DSU.join(idx+1, idx);
ans[i]=tot;
}
for(int i=0; i<Q; i++){
cin >> Y;
cout << ans[upper_bound(A, A+N, mp(Y, INF))-A-1] << nl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8160 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
4 ms |
8140 KB |
Output is correct |
10 |
Correct |
4 ms |
8160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8160 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
4 ms |
8140 KB |
Output is correct |
10 |
Correct |
4 ms |
8160 KB |
Output is correct |
11 |
Correct |
5 ms |
8044 KB |
Output is correct |
12 |
Correct |
4 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
4 ms |
8140 KB |
Output is correct |
15 |
Correct |
4 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8160 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
4 ms |
8140 KB |
Output is correct |
10 |
Correct |
4 ms |
8160 KB |
Output is correct |
11 |
Correct |
5 ms |
8044 KB |
Output is correct |
12 |
Correct |
4 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
4 ms |
8140 KB |
Output is correct |
15 |
Correct |
4 ms |
8140 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8140 KB |
Output is correct |
18 |
Correct |
4 ms |
8100 KB |
Output is correct |
19 |
Correct |
4 ms |
8140 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8160 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
4 ms |
8140 KB |
Output is correct |
10 |
Correct |
4 ms |
8160 KB |
Output is correct |
11 |
Correct |
5 ms |
8044 KB |
Output is correct |
12 |
Correct |
4 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
4 ms |
8140 KB |
Output is correct |
15 |
Correct |
4 ms |
8140 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8140 KB |
Output is correct |
18 |
Correct |
4 ms |
8100 KB |
Output is correct |
19 |
Correct |
4 ms |
8140 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
21 |
Correct |
4 ms |
8140 KB |
Output is correct |
22 |
Correct |
4 ms |
8140 KB |
Output is correct |
23 |
Correct |
4 ms |
8140 KB |
Output is correct |
24 |
Correct |
4 ms |
8140 KB |
Output is correct |
25 |
Correct |
5 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
10064 KB |
Output is correct |
2 |
Correct |
24 ms |
10060 KB |
Output is correct |
3 |
Correct |
22 ms |
9904 KB |
Output is correct |
4 |
Correct |
20 ms |
9920 KB |
Output is correct |
5 |
Correct |
23 ms |
9864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
10856 KB |
Output is correct |
2 |
Correct |
36 ms |
10984 KB |
Output is correct |
3 |
Correct |
35 ms |
10956 KB |
Output is correct |
4 |
Correct |
35 ms |
10948 KB |
Output is correct |
5 |
Correct |
38 ms |
10864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
10868 KB |
Output is correct |
2 |
Correct |
40 ms |
10820 KB |
Output is correct |
3 |
Correct |
42 ms |
10880 KB |
Output is correct |
4 |
Correct |
40 ms |
10968 KB |
Output is correct |
5 |
Correct |
42 ms |
10960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8160 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
4 ms |
8140 KB |
Output is correct |
10 |
Correct |
4 ms |
8160 KB |
Output is correct |
11 |
Correct |
21 ms |
10064 KB |
Output is correct |
12 |
Correct |
24 ms |
10060 KB |
Output is correct |
13 |
Correct |
22 ms |
9904 KB |
Output is correct |
14 |
Correct |
20 ms |
9920 KB |
Output is correct |
15 |
Correct |
23 ms |
9864 KB |
Output is correct |
16 |
Correct |
22 ms |
10000 KB |
Output is correct |
17 |
Correct |
21 ms |
10072 KB |
Output is correct |
18 |
Correct |
22 ms |
10108 KB |
Output is correct |
19 |
Correct |
21 ms |
9876 KB |
Output is correct |
20 |
Correct |
23 ms |
10024 KB |
Output is correct |
21 |
Correct |
22 ms |
9924 KB |
Output is correct |
22 |
Correct |
21 ms |
9884 KB |
Output is correct |
23 |
Correct |
23 ms |
10088 KB |
Output is correct |
24 |
Correct |
21 ms |
9864 KB |
Output is correct |
25 |
Correct |
21 ms |
9924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8160 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
4 ms |
8140 KB |
Output is correct |
10 |
Correct |
4 ms |
8160 KB |
Output is correct |
11 |
Correct |
5 ms |
8044 KB |
Output is correct |
12 |
Correct |
4 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
4 ms |
8140 KB |
Output is correct |
15 |
Correct |
4 ms |
8140 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8140 KB |
Output is correct |
18 |
Correct |
4 ms |
8100 KB |
Output is correct |
19 |
Correct |
4 ms |
8140 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
21 |
Correct |
4 ms |
8140 KB |
Output is correct |
22 |
Correct |
4 ms |
8140 KB |
Output is correct |
23 |
Correct |
4 ms |
8140 KB |
Output is correct |
24 |
Correct |
4 ms |
8140 KB |
Output is correct |
25 |
Correct |
5 ms |
8140 KB |
Output is correct |
26 |
Correct |
21 ms |
10064 KB |
Output is correct |
27 |
Correct |
24 ms |
10060 KB |
Output is correct |
28 |
Correct |
22 ms |
9904 KB |
Output is correct |
29 |
Correct |
20 ms |
9920 KB |
Output is correct |
30 |
Correct |
23 ms |
9864 KB |
Output is correct |
31 |
Correct |
35 ms |
10856 KB |
Output is correct |
32 |
Correct |
36 ms |
10984 KB |
Output is correct |
33 |
Correct |
35 ms |
10956 KB |
Output is correct |
34 |
Correct |
35 ms |
10948 KB |
Output is correct |
35 |
Correct |
38 ms |
10864 KB |
Output is correct |
36 |
Correct |
40 ms |
10868 KB |
Output is correct |
37 |
Correct |
40 ms |
10820 KB |
Output is correct |
38 |
Correct |
42 ms |
10880 KB |
Output is correct |
39 |
Correct |
40 ms |
10968 KB |
Output is correct |
40 |
Correct |
42 ms |
10960 KB |
Output is correct |
41 |
Correct |
22 ms |
10000 KB |
Output is correct |
42 |
Correct |
21 ms |
10072 KB |
Output is correct |
43 |
Correct |
22 ms |
10108 KB |
Output is correct |
44 |
Correct |
21 ms |
9876 KB |
Output is correct |
45 |
Correct |
23 ms |
10024 KB |
Output is correct |
46 |
Correct |
22 ms |
9924 KB |
Output is correct |
47 |
Correct |
21 ms |
9884 KB |
Output is correct |
48 |
Correct |
23 ms |
10088 KB |
Output is correct |
49 |
Correct |
21 ms |
9864 KB |
Output is correct |
50 |
Correct |
21 ms |
9924 KB |
Output is correct |
51 |
Correct |
44 ms |
10744 KB |
Output is correct |
52 |
Correct |
49 ms |
10564 KB |
Output is correct |
53 |
Correct |
44 ms |
10820 KB |
Output is correct |
54 |
Correct |
48 ms |
10608 KB |
Output is correct |
55 |
Correct |
47 ms |
10864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8140 KB |
Output is correct |
5 |
Correct |
4 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8160 KB |
Output is correct |
7 |
Correct |
4 ms |
8140 KB |
Output is correct |
8 |
Correct |
4 ms |
8140 KB |
Output is correct |
9 |
Correct |
4 ms |
8140 KB |
Output is correct |
10 |
Correct |
4 ms |
8160 KB |
Output is correct |
11 |
Correct |
5 ms |
8044 KB |
Output is correct |
12 |
Correct |
4 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
4 ms |
8140 KB |
Output is correct |
15 |
Correct |
4 ms |
8140 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
4 ms |
8140 KB |
Output is correct |
18 |
Correct |
4 ms |
8100 KB |
Output is correct |
19 |
Correct |
4 ms |
8140 KB |
Output is correct |
20 |
Correct |
4 ms |
8140 KB |
Output is correct |
21 |
Correct |
4 ms |
8140 KB |
Output is correct |
22 |
Correct |
4 ms |
8140 KB |
Output is correct |
23 |
Correct |
4 ms |
8140 KB |
Output is correct |
24 |
Correct |
4 ms |
8140 KB |
Output is correct |
25 |
Correct |
5 ms |
8140 KB |
Output is correct |
26 |
Correct |
21 ms |
10064 KB |
Output is correct |
27 |
Correct |
24 ms |
10060 KB |
Output is correct |
28 |
Correct |
22 ms |
9904 KB |
Output is correct |
29 |
Correct |
20 ms |
9920 KB |
Output is correct |
30 |
Correct |
23 ms |
9864 KB |
Output is correct |
31 |
Correct |
35 ms |
10856 KB |
Output is correct |
32 |
Correct |
36 ms |
10984 KB |
Output is correct |
33 |
Correct |
35 ms |
10956 KB |
Output is correct |
34 |
Correct |
35 ms |
10948 KB |
Output is correct |
35 |
Correct |
38 ms |
10864 KB |
Output is correct |
36 |
Correct |
40 ms |
10868 KB |
Output is correct |
37 |
Correct |
40 ms |
10820 KB |
Output is correct |
38 |
Correct |
42 ms |
10880 KB |
Output is correct |
39 |
Correct |
40 ms |
10968 KB |
Output is correct |
40 |
Correct |
42 ms |
10960 KB |
Output is correct |
41 |
Correct |
22 ms |
10000 KB |
Output is correct |
42 |
Correct |
21 ms |
10072 KB |
Output is correct |
43 |
Correct |
22 ms |
10108 KB |
Output is correct |
44 |
Correct |
21 ms |
9876 KB |
Output is correct |
45 |
Correct |
23 ms |
10024 KB |
Output is correct |
46 |
Correct |
22 ms |
9924 KB |
Output is correct |
47 |
Correct |
21 ms |
9884 KB |
Output is correct |
48 |
Correct |
23 ms |
10088 KB |
Output is correct |
49 |
Correct |
21 ms |
9864 KB |
Output is correct |
50 |
Correct |
21 ms |
9924 KB |
Output is correct |
51 |
Correct |
44 ms |
10744 KB |
Output is correct |
52 |
Correct |
49 ms |
10564 KB |
Output is correct |
53 |
Correct |
44 ms |
10820 KB |
Output is correct |
54 |
Correct |
48 ms |
10608 KB |
Output is correct |
55 |
Correct |
47 ms |
10864 KB |
Output is correct |
56 |
Correct |
655 ms |
34032 KB |
Output is correct |
57 |
Correct |
665 ms |
34372 KB |
Output is correct |
58 |
Correct |
617 ms |
32840 KB |
Output is correct |
59 |
Correct |
646 ms |
33476 KB |
Output is correct |
60 |
Correct |
696 ms |
35024 KB |
Output is correct |