#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
const int maxn = 1e6 + 5;
int n, q;
vl arr;
ll parent[maxn];
ll sz[maxn];
bool on[maxn];
int find(int v){
if(v == parent[v])
return v;
return parent[v] = find(parent[v]);
}
ll rez = 0;
void mrg(int a, int b){
a = find(a);
b = find(b);
if(a != b){
rez -= (sz[a] * (sz[a] + 1) * 1LL) / 2;
rez -= (sz[b] * (sz[b] + 1)*1LL) / 2;
sz[a] += sz[b];
rez += (sz[a] * (sz[a] + 1)*1LL) / 2;
parent[b] = a;
}
}
vl G[maxn];
ll ans[maxn];
int main(){
cin>>n>>q;
arr.resize(n);
for(int i = 0; i < n; i++){
parent[i] = i;
sz[i] = 1;
}
for(int i = 0; i < n; i++){
cin>>arr[i];
G[arr[i]].pb(i);
}
for(int i = 1; i <= 1000000; i++){
for(int x : G[i]){
++rez;
on[x] = 1;
if(x && on[x-1]) mrg(x, x-1);
if(x != n-1 && on[x+1]) mrg(x, x + 1);
}
ans[i] = rez;
}
for(int i = 0; i < q; i++){
ll a;
cin>>a;
cout<<ans[a]<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
17 ms |
31572 KB |
Output is correct |
3 |
Correct |
17 ms |
31632 KB |
Output is correct |
4 |
Correct |
16 ms |
31572 KB |
Output is correct |
5 |
Correct |
17 ms |
31536 KB |
Output is correct |
6 |
Correct |
17 ms |
31580 KB |
Output is correct |
7 |
Correct |
17 ms |
31572 KB |
Output is correct |
8 |
Correct |
17 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31572 KB |
Output is correct |
10 |
Correct |
17 ms |
31608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
17 ms |
31572 KB |
Output is correct |
3 |
Correct |
17 ms |
31632 KB |
Output is correct |
4 |
Correct |
16 ms |
31572 KB |
Output is correct |
5 |
Correct |
17 ms |
31536 KB |
Output is correct |
6 |
Correct |
17 ms |
31580 KB |
Output is correct |
7 |
Correct |
17 ms |
31572 KB |
Output is correct |
8 |
Correct |
17 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31572 KB |
Output is correct |
10 |
Correct |
17 ms |
31608 KB |
Output is correct |
11 |
Correct |
16 ms |
31572 KB |
Output is correct |
12 |
Correct |
16 ms |
31580 KB |
Output is correct |
13 |
Correct |
16 ms |
31604 KB |
Output is correct |
14 |
Correct |
16 ms |
31600 KB |
Output is correct |
15 |
Correct |
18 ms |
31608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
17 ms |
31572 KB |
Output is correct |
3 |
Correct |
17 ms |
31632 KB |
Output is correct |
4 |
Correct |
16 ms |
31572 KB |
Output is correct |
5 |
Correct |
17 ms |
31536 KB |
Output is correct |
6 |
Correct |
17 ms |
31580 KB |
Output is correct |
7 |
Correct |
17 ms |
31572 KB |
Output is correct |
8 |
Correct |
17 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31572 KB |
Output is correct |
10 |
Correct |
17 ms |
31608 KB |
Output is correct |
11 |
Correct |
16 ms |
31572 KB |
Output is correct |
12 |
Correct |
16 ms |
31580 KB |
Output is correct |
13 |
Correct |
16 ms |
31604 KB |
Output is correct |
14 |
Correct |
16 ms |
31600 KB |
Output is correct |
15 |
Correct |
18 ms |
31608 KB |
Output is correct |
16 |
Correct |
18 ms |
31572 KB |
Output is correct |
17 |
Correct |
16 ms |
31700 KB |
Output is correct |
18 |
Correct |
16 ms |
31572 KB |
Output is correct |
19 |
Correct |
19 ms |
31556 KB |
Output is correct |
20 |
Correct |
20 ms |
31620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
17 ms |
31572 KB |
Output is correct |
3 |
Correct |
17 ms |
31632 KB |
Output is correct |
4 |
Correct |
16 ms |
31572 KB |
Output is correct |
5 |
Correct |
17 ms |
31536 KB |
Output is correct |
6 |
Correct |
17 ms |
31580 KB |
Output is correct |
7 |
Correct |
17 ms |
31572 KB |
Output is correct |
8 |
Correct |
17 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31572 KB |
Output is correct |
10 |
Correct |
17 ms |
31608 KB |
Output is correct |
11 |
Correct |
16 ms |
31572 KB |
Output is correct |
12 |
Correct |
16 ms |
31580 KB |
Output is correct |
13 |
Correct |
16 ms |
31604 KB |
Output is correct |
14 |
Correct |
16 ms |
31600 KB |
Output is correct |
15 |
Correct |
18 ms |
31608 KB |
Output is correct |
16 |
Correct |
18 ms |
31572 KB |
Output is correct |
17 |
Correct |
16 ms |
31700 KB |
Output is correct |
18 |
Correct |
16 ms |
31572 KB |
Output is correct |
19 |
Correct |
19 ms |
31556 KB |
Output is correct |
20 |
Correct |
20 ms |
31620 KB |
Output is correct |
21 |
Correct |
18 ms |
31660 KB |
Output is correct |
22 |
Correct |
20 ms |
31624 KB |
Output is correct |
23 |
Correct |
17 ms |
31572 KB |
Output is correct |
24 |
Correct |
22 ms |
31620 KB |
Output is correct |
25 |
Correct |
19 ms |
31572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
36028 KB |
Output is correct |
2 |
Correct |
75 ms |
37708 KB |
Output is correct |
3 |
Correct |
55 ms |
36348 KB |
Output is correct |
4 |
Correct |
70 ms |
37028 KB |
Output is correct |
5 |
Correct |
55 ms |
36300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
188 ms |
37712 KB |
Output is correct |
2 |
Correct |
203 ms |
38964 KB |
Output is correct |
3 |
Correct |
196 ms |
38760 KB |
Output is correct |
4 |
Correct |
189 ms |
39108 KB |
Output is correct |
5 |
Correct |
187 ms |
38680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
190 ms |
37924 KB |
Output is correct |
2 |
Correct |
207 ms |
38980 KB |
Output is correct |
3 |
Correct |
202 ms |
38896 KB |
Output is correct |
4 |
Correct |
192 ms |
39376 KB |
Output is correct |
5 |
Correct |
203 ms |
39116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
17 ms |
31572 KB |
Output is correct |
3 |
Correct |
17 ms |
31632 KB |
Output is correct |
4 |
Correct |
16 ms |
31572 KB |
Output is correct |
5 |
Correct |
17 ms |
31536 KB |
Output is correct |
6 |
Correct |
17 ms |
31580 KB |
Output is correct |
7 |
Correct |
17 ms |
31572 KB |
Output is correct |
8 |
Correct |
17 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31572 KB |
Output is correct |
10 |
Correct |
17 ms |
31608 KB |
Output is correct |
11 |
Correct |
54 ms |
36028 KB |
Output is correct |
12 |
Correct |
75 ms |
37708 KB |
Output is correct |
13 |
Correct |
55 ms |
36348 KB |
Output is correct |
14 |
Correct |
70 ms |
37028 KB |
Output is correct |
15 |
Correct |
55 ms |
36300 KB |
Output is correct |
16 |
Correct |
51 ms |
36264 KB |
Output is correct |
17 |
Correct |
73 ms |
37500 KB |
Output is correct |
18 |
Correct |
76 ms |
37576 KB |
Output is correct |
19 |
Correct |
54 ms |
36316 KB |
Output is correct |
20 |
Correct |
68 ms |
37452 KB |
Output is correct |
21 |
Correct |
54 ms |
36284 KB |
Output is correct |
22 |
Correct |
70 ms |
37196 KB |
Output is correct |
23 |
Correct |
67 ms |
36684 KB |
Output is correct |
24 |
Correct |
65 ms |
37104 KB |
Output is correct |
25 |
Correct |
54 ms |
36540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
17 ms |
31572 KB |
Output is correct |
3 |
Correct |
17 ms |
31632 KB |
Output is correct |
4 |
Correct |
16 ms |
31572 KB |
Output is correct |
5 |
Correct |
17 ms |
31536 KB |
Output is correct |
6 |
Correct |
17 ms |
31580 KB |
Output is correct |
7 |
Correct |
17 ms |
31572 KB |
Output is correct |
8 |
Correct |
17 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31572 KB |
Output is correct |
10 |
Correct |
17 ms |
31608 KB |
Output is correct |
11 |
Correct |
16 ms |
31572 KB |
Output is correct |
12 |
Correct |
16 ms |
31580 KB |
Output is correct |
13 |
Correct |
16 ms |
31604 KB |
Output is correct |
14 |
Correct |
16 ms |
31600 KB |
Output is correct |
15 |
Correct |
18 ms |
31608 KB |
Output is correct |
16 |
Correct |
18 ms |
31572 KB |
Output is correct |
17 |
Correct |
16 ms |
31700 KB |
Output is correct |
18 |
Correct |
16 ms |
31572 KB |
Output is correct |
19 |
Correct |
19 ms |
31556 KB |
Output is correct |
20 |
Correct |
20 ms |
31620 KB |
Output is correct |
21 |
Correct |
18 ms |
31660 KB |
Output is correct |
22 |
Correct |
20 ms |
31624 KB |
Output is correct |
23 |
Correct |
17 ms |
31572 KB |
Output is correct |
24 |
Correct |
22 ms |
31620 KB |
Output is correct |
25 |
Correct |
19 ms |
31572 KB |
Output is correct |
26 |
Correct |
54 ms |
36028 KB |
Output is correct |
27 |
Correct |
75 ms |
37708 KB |
Output is correct |
28 |
Correct |
55 ms |
36348 KB |
Output is correct |
29 |
Correct |
70 ms |
37028 KB |
Output is correct |
30 |
Correct |
55 ms |
36300 KB |
Output is correct |
31 |
Correct |
188 ms |
37712 KB |
Output is correct |
32 |
Correct |
203 ms |
38964 KB |
Output is correct |
33 |
Correct |
196 ms |
38760 KB |
Output is correct |
34 |
Correct |
189 ms |
39108 KB |
Output is correct |
35 |
Correct |
187 ms |
38680 KB |
Output is correct |
36 |
Correct |
190 ms |
37924 KB |
Output is correct |
37 |
Correct |
207 ms |
38980 KB |
Output is correct |
38 |
Correct |
202 ms |
38896 KB |
Output is correct |
39 |
Correct |
192 ms |
39376 KB |
Output is correct |
40 |
Correct |
203 ms |
39116 KB |
Output is correct |
41 |
Correct |
51 ms |
36264 KB |
Output is correct |
42 |
Correct |
73 ms |
37500 KB |
Output is correct |
43 |
Correct |
76 ms |
37576 KB |
Output is correct |
44 |
Correct |
54 ms |
36316 KB |
Output is correct |
45 |
Correct |
68 ms |
37452 KB |
Output is correct |
46 |
Correct |
54 ms |
36284 KB |
Output is correct |
47 |
Correct |
70 ms |
37196 KB |
Output is correct |
48 |
Correct |
67 ms |
36684 KB |
Output is correct |
49 |
Correct |
65 ms |
37104 KB |
Output is correct |
50 |
Correct |
54 ms |
36540 KB |
Output is correct |
51 |
Correct |
206 ms |
38056 KB |
Output is correct |
52 |
Correct |
245 ms |
38636 KB |
Output is correct |
53 |
Correct |
204 ms |
38036 KB |
Output is correct |
54 |
Correct |
224 ms |
38540 KB |
Output is correct |
55 |
Correct |
198 ms |
38092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31572 KB |
Output is correct |
2 |
Correct |
17 ms |
31572 KB |
Output is correct |
3 |
Correct |
17 ms |
31632 KB |
Output is correct |
4 |
Correct |
16 ms |
31572 KB |
Output is correct |
5 |
Correct |
17 ms |
31536 KB |
Output is correct |
6 |
Correct |
17 ms |
31580 KB |
Output is correct |
7 |
Correct |
17 ms |
31572 KB |
Output is correct |
8 |
Correct |
17 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31572 KB |
Output is correct |
10 |
Correct |
17 ms |
31608 KB |
Output is correct |
11 |
Correct |
16 ms |
31572 KB |
Output is correct |
12 |
Correct |
16 ms |
31580 KB |
Output is correct |
13 |
Correct |
16 ms |
31604 KB |
Output is correct |
14 |
Correct |
16 ms |
31600 KB |
Output is correct |
15 |
Correct |
18 ms |
31608 KB |
Output is correct |
16 |
Correct |
18 ms |
31572 KB |
Output is correct |
17 |
Correct |
16 ms |
31700 KB |
Output is correct |
18 |
Correct |
16 ms |
31572 KB |
Output is correct |
19 |
Correct |
19 ms |
31556 KB |
Output is correct |
20 |
Correct |
20 ms |
31620 KB |
Output is correct |
21 |
Correct |
18 ms |
31660 KB |
Output is correct |
22 |
Correct |
20 ms |
31624 KB |
Output is correct |
23 |
Correct |
17 ms |
31572 KB |
Output is correct |
24 |
Correct |
22 ms |
31620 KB |
Output is correct |
25 |
Correct |
19 ms |
31572 KB |
Output is correct |
26 |
Correct |
54 ms |
36028 KB |
Output is correct |
27 |
Correct |
75 ms |
37708 KB |
Output is correct |
28 |
Correct |
55 ms |
36348 KB |
Output is correct |
29 |
Correct |
70 ms |
37028 KB |
Output is correct |
30 |
Correct |
55 ms |
36300 KB |
Output is correct |
31 |
Correct |
188 ms |
37712 KB |
Output is correct |
32 |
Correct |
203 ms |
38964 KB |
Output is correct |
33 |
Correct |
196 ms |
38760 KB |
Output is correct |
34 |
Correct |
189 ms |
39108 KB |
Output is correct |
35 |
Correct |
187 ms |
38680 KB |
Output is correct |
36 |
Correct |
190 ms |
37924 KB |
Output is correct |
37 |
Correct |
207 ms |
38980 KB |
Output is correct |
38 |
Correct |
202 ms |
38896 KB |
Output is correct |
39 |
Correct |
192 ms |
39376 KB |
Output is correct |
40 |
Correct |
203 ms |
39116 KB |
Output is correct |
41 |
Correct |
51 ms |
36264 KB |
Output is correct |
42 |
Correct |
73 ms |
37500 KB |
Output is correct |
43 |
Correct |
76 ms |
37576 KB |
Output is correct |
44 |
Correct |
54 ms |
36316 KB |
Output is correct |
45 |
Correct |
68 ms |
37452 KB |
Output is correct |
46 |
Correct |
54 ms |
36284 KB |
Output is correct |
47 |
Correct |
70 ms |
37196 KB |
Output is correct |
48 |
Correct |
67 ms |
36684 KB |
Output is correct |
49 |
Correct |
65 ms |
37104 KB |
Output is correct |
50 |
Correct |
54 ms |
36540 KB |
Output is correct |
51 |
Correct |
206 ms |
38056 KB |
Output is correct |
52 |
Correct |
245 ms |
38636 KB |
Output is correct |
53 |
Correct |
204 ms |
38036 KB |
Output is correct |
54 |
Correct |
224 ms |
38540 KB |
Output is correct |
55 |
Correct |
198 ms |
38092 KB |
Output is correct |
56 |
Execution timed out |
1094 ms |
85788 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |