#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define pb push_back
#define fi first
#define se second
const ll N = 1e6+5;
ll n,q,ans,tmp;
ll sz[N],par[N],ansq[N],a[N];
pii b[N],x[N];
ll root(ll x) {
if(par[x] == x) return x;
return par[x] = root(par[x]);
}
void join(ll y, ll z) {
ll ry = root(y);
ll rz = root(z);
if(ry == rz) return;
par[ry] = rz;
ans -= (sz[rz] + sz[ry]);
ans -= (sz[rz]*(sz[rz]-1))/2;
ans -= (sz[ry]*(sz[ry]-1))/2;
sz[rz] += sz[ry];
ans += (sz[rz]*(sz[rz]-1))/2 + sz[rz];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
for(int i=1; i<=n; i++) {
cin >> a[i];
b[i].fi = a[i]; b[i].se = i;
par[i] = i;
}
sort(b+1,b+n+1);
for(int i=1; i<=q; i++) {
cin >> x[i].fi;
x[i].se = i;
}
sort(x+1,x+q+1);
ll idx = 1;
for(int i=1; i<=q; i++) {
while(idx <= n && b[idx].fi <= x[i].fi) {
ll var = b[idx].se;
sz[var] = 1;
ans++;
if(var > 1 && sz[var-1] > 0) join(var-1,var);
if(var < n && sz[var+1] > 0) join(var+1,var);
idx++;
}
ansq[x[i].se] = ans;
}
for(int i=1; i<=q; i++) cout << ansq[i] << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10588 KB |
Output is correct |
12 |
Correct |
2 ms |
10712 KB |
Output is correct |
13 |
Correct |
2 ms |
10840 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10588 KB |
Output is correct |
12 |
Correct |
2 ms |
10712 KB |
Output is correct |
13 |
Correct |
2 ms |
10840 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10840 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10588 KB |
Output is correct |
12 |
Correct |
2 ms |
10712 KB |
Output is correct |
13 |
Correct |
2 ms |
10840 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10840 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
3 ms |
10708 KB |
Output is correct |
22 |
Correct |
3 ms |
10584 KB |
Output is correct |
23 |
Correct |
3 ms |
10584 KB |
Output is correct |
24 |
Correct |
3 ms |
10584 KB |
Output is correct |
25 |
Correct |
3 ms |
10836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
15168 KB |
Output is correct |
2 |
Correct |
16 ms |
15452 KB |
Output is correct |
3 |
Correct |
17 ms |
15196 KB |
Output is correct |
4 |
Correct |
15 ms |
15432 KB |
Output is correct |
5 |
Correct |
16 ms |
15192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
21072 KB |
Output is correct |
2 |
Correct |
130 ms |
21224 KB |
Output is correct |
3 |
Correct |
152 ms |
21124 KB |
Output is correct |
4 |
Correct |
132 ms |
20984 KB |
Output is correct |
5 |
Correct |
132 ms |
21044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
21076 KB |
Output is correct |
2 |
Correct |
126 ms |
21076 KB |
Output is correct |
3 |
Correct |
141 ms |
21332 KB |
Output is correct |
4 |
Correct |
122 ms |
21096 KB |
Output is correct |
5 |
Correct |
132 ms |
21180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
17 ms |
15168 KB |
Output is correct |
12 |
Correct |
16 ms |
15452 KB |
Output is correct |
13 |
Correct |
17 ms |
15196 KB |
Output is correct |
14 |
Correct |
15 ms |
15432 KB |
Output is correct |
15 |
Correct |
16 ms |
15192 KB |
Output is correct |
16 |
Correct |
15 ms |
15196 KB |
Output is correct |
17 |
Correct |
15 ms |
15220 KB |
Output is correct |
18 |
Correct |
15 ms |
15476 KB |
Output is correct |
19 |
Correct |
17 ms |
15196 KB |
Output is correct |
20 |
Correct |
15 ms |
15448 KB |
Output is correct |
21 |
Correct |
15 ms |
15196 KB |
Output is correct |
22 |
Correct |
14 ms |
15196 KB |
Output is correct |
23 |
Correct |
15 ms |
15124 KB |
Output is correct |
24 |
Correct |
13 ms |
15196 KB |
Output is correct |
25 |
Correct |
15 ms |
15196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10588 KB |
Output is correct |
12 |
Correct |
2 ms |
10712 KB |
Output is correct |
13 |
Correct |
2 ms |
10840 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10840 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
3 ms |
10708 KB |
Output is correct |
22 |
Correct |
3 ms |
10584 KB |
Output is correct |
23 |
Correct |
3 ms |
10584 KB |
Output is correct |
24 |
Correct |
3 ms |
10584 KB |
Output is correct |
25 |
Correct |
3 ms |
10836 KB |
Output is correct |
26 |
Correct |
17 ms |
15168 KB |
Output is correct |
27 |
Correct |
16 ms |
15452 KB |
Output is correct |
28 |
Correct |
17 ms |
15196 KB |
Output is correct |
29 |
Correct |
15 ms |
15432 KB |
Output is correct |
30 |
Correct |
16 ms |
15192 KB |
Output is correct |
31 |
Correct |
122 ms |
21072 KB |
Output is correct |
32 |
Correct |
130 ms |
21224 KB |
Output is correct |
33 |
Correct |
152 ms |
21124 KB |
Output is correct |
34 |
Correct |
132 ms |
20984 KB |
Output is correct |
35 |
Correct |
132 ms |
21044 KB |
Output is correct |
36 |
Correct |
123 ms |
21076 KB |
Output is correct |
37 |
Correct |
126 ms |
21076 KB |
Output is correct |
38 |
Correct |
141 ms |
21332 KB |
Output is correct |
39 |
Correct |
122 ms |
21096 KB |
Output is correct |
40 |
Correct |
132 ms |
21180 KB |
Output is correct |
41 |
Correct |
15 ms |
15196 KB |
Output is correct |
42 |
Correct |
15 ms |
15220 KB |
Output is correct |
43 |
Correct |
15 ms |
15476 KB |
Output is correct |
44 |
Correct |
17 ms |
15196 KB |
Output is correct |
45 |
Correct |
15 ms |
15448 KB |
Output is correct |
46 |
Correct |
15 ms |
15196 KB |
Output is correct |
47 |
Correct |
14 ms |
15196 KB |
Output is correct |
48 |
Correct |
15 ms |
15124 KB |
Output is correct |
49 |
Correct |
13 ms |
15196 KB |
Output is correct |
50 |
Correct |
15 ms |
15196 KB |
Output is correct |
51 |
Correct |
138 ms |
20948 KB |
Output is correct |
52 |
Correct |
138 ms |
20820 KB |
Output is correct |
53 |
Correct |
137 ms |
21020 KB |
Output is correct |
54 |
Correct |
134 ms |
20984 KB |
Output is correct |
55 |
Correct |
135 ms |
20792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10588 KB |
Output is correct |
12 |
Correct |
2 ms |
10712 KB |
Output is correct |
13 |
Correct |
2 ms |
10840 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10840 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
3 ms |
10708 KB |
Output is correct |
22 |
Correct |
3 ms |
10584 KB |
Output is correct |
23 |
Correct |
3 ms |
10584 KB |
Output is correct |
24 |
Correct |
3 ms |
10584 KB |
Output is correct |
25 |
Correct |
3 ms |
10836 KB |
Output is correct |
26 |
Correct |
17 ms |
15168 KB |
Output is correct |
27 |
Correct |
16 ms |
15452 KB |
Output is correct |
28 |
Correct |
17 ms |
15196 KB |
Output is correct |
29 |
Correct |
15 ms |
15432 KB |
Output is correct |
30 |
Correct |
16 ms |
15192 KB |
Output is correct |
31 |
Correct |
122 ms |
21072 KB |
Output is correct |
32 |
Correct |
130 ms |
21224 KB |
Output is correct |
33 |
Correct |
152 ms |
21124 KB |
Output is correct |
34 |
Correct |
132 ms |
20984 KB |
Output is correct |
35 |
Correct |
132 ms |
21044 KB |
Output is correct |
36 |
Correct |
123 ms |
21076 KB |
Output is correct |
37 |
Correct |
126 ms |
21076 KB |
Output is correct |
38 |
Correct |
141 ms |
21332 KB |
Output is correct |
39 |
Correct |
122 ms |
21096 KB |
Output is correct |
40 |
Correct |
132 ms |
21180 KB |
Output is correct |
41 |
Correct |
15 ms |
15196 KB |
Output is correct |
42 |
Correct |
15 ms |
15220 KB |
Output is correct |
43 |
Correct |
15 ms |
15476 KB |
Output is correct |
44 |
Correct |
17 ms |
15196 KB |
Output is correct |
45 |
Correct |
15 ms |
15448 KB |
Output is correct |
46 |
Correct |
15 ms |
15196 KB |
Output is correct |
47 |
Correct |
14 ms |
15196 KB |
Output is correct |
48 |
Correct |
15 ms |
15124 KB |
Output is correct |
49 |
Correct |
13 ms |
15196 KB |
Output is correct |
50 |
Correct |
15 ms |
15196 KB |
Output is correct |
51 |
Correct |
138 ms |
20948 KB |
Output is correct |
52 |
Correct |
138 ms |
20820 KB |
Output is correct |
53 |
Correct |
137 ms |
21020 KB |
Output is correct |
54 |
Correct |
134 ms |
20984 KB |
Output is correct |
55 |
Correct |
135 ms |
20792 KB |
Output is correct |
56 |
Execution timed out |
1034 ms |
79908 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |