#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,qu;
ll ans[1000001],sum;
vector<int> h[1000001];
set<int> s;
ll cal(ll x) {
return x*(x+1)/2;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>qu;
s.insert(0);
s.insert(n+1);
for (int i=1; i<=n; ++i) {
int a; cin>>a;
h[a].push_back(i);
}
sum=cal(n);
for (int i=1000000; i>0; --i) {
ans[i]=sum;
for (auto j : h[i]) {
auto it=s.upper_bound(j);
int r=*it, l=*(--it);
sum-=cal(r-l-1);
sum+=cal(j-l-1);
sum+=cal(r-j-1);
s.insert(j);
}
}
for (int i=1; i<=qu; ++i) {
int x; cin>>x;
cout<<ans[x]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
31616 KB |
Output is correct |
2 |
Correct |
19 ms |
31632 KB |
Output is correct |
3 |
Correct |
19 ms |
31568 KB |
Output is correct |
4 |
Correct |
19 ms |
31596 KB |
Output is correct |
5 |
Correct |
20 ms |
31548 KB |
Output is correct |
6 |
Correct |
20 ms |
31572 KB |
Output is correct |
7 |
Correct |
20 ms |
31580 KB |
Output is correct |
8 |
Correct |
19 ms |
31536 KB |
Output is correct |
9 |
Correct |
20 ms |
31504 KB |
Output is correct |
10 |
Correct |
19 ms |
31556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
31616 KB |
Output is correct |
2 |
Correct |
19 ms |
31632 KB |
Output is correct |
3 |
Correct |
19 ms |
31568 KB |
Output is correct |
4 |
Correct |
19 ms |
31596 KB |
Output is correct |
5 |
Correct |
20 ms |
31548 KB |
Output is correct |
6 |
Correct |
20 ms |
31572 KB |
Output is correct |
7 |
Correct |
20 ms |
31580 KB |
Output is correct |
8 |
Correct |
19 ms |
31536 KB |
Output is correct |
9 |
Correct |
20 ms |
31504 KB |
Output is correct |
10 |
Correct |
19 ms |
31556 KB |
Output is correct |
11 |
Correct |
20 ms |
31572 KB |
Output is correct |
12 |
Correct |
19 ms |
31572 KB |
Output is correct |
13 |
Correct |
19 ms |
31620 KB |
Output is correct |
14 |
Correct |
19 ms |
31564 KB |
Output is correct |
15 |
Correct |
23 ms |
31572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
31616 KB |
Output is correct |
2 |
Correct |
19 ms |
31632 KB |
Output is correct |
3 |
Correct |
19 ms |
31568 KB |
Output is correct |
4 |
Correct |
19 ms |
31596 KB |
Output is correct |
5 |
Correct |
20 ms |
31548 KB |
Output is correct |
6 |
Correct |
20 ms |
31572 KB |
Output is correct |
7 |
Correct |
20 ms |
31580 KB |
Output is correct |
8 |
Correct |
19 ms |
31536 KB |
Output is correct |
9 |
Correct |
20 ms |
31504 KB |
Output is correct |
10 |
Correct |
19 ms |
31556 KB |
Output is correct |
11 |
Correct |
20 ms |
31572 KB |
Output is correct |
12 |
Correct |
19 ms |
31572 KB |
Output is correct |
13 |
Correct |
19 ms |
31620 KB |
Output is correct |
14 |
Correct |
19 ms |
31564 KB |
Output is correct |
15 |
Correct |
23 ms |
31572 KB |
Output is correct |
16 |
Correct |
19 ms |
31620 KB |
Output is correct |
17 |
Correct |
20 ms |
31620 KB |
Output is correct |
18 |
Correct |
19 ms |
31572 KB |
Output is correct |
19 |
Correct |
20 ms |
31684 KB |
Output is correct |
20 |
Correct |
20 ms |
31572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
31616 KB |
Output is correct |
2 |
Correct |
19 ms |
31632 KB |
Output is correct |
3 |
Correct |
19 ms |
31568 KB |
Output is correct |
4 |
Correct |
19 ms |
31596 KB |
Output is correct |
5 |
Correct |
20 ms |
31548 KB |
Output is correct |
6 |
Correct |
20 ms |
31572 KB |
Output is correct |
7 |
Correct |
20 ms |
31580 KB |
Output is correct |
8 |
Correct |
19 ms |
31536 KB |
Output is correct |
9 |
Correct |
20 ms |
31504 KB |
Output is correct |
10 |
Correct |
19 ms |
31556 KB |
Output is correct |
11 |
Correct |
20 ms |
31572 KB |
Output is correct |
12 |
Correct |
19 ms |
31572 KB |
Output is correct |
13 |
Correct |
19 ms |
31620 KB |
Output is correct |
14 |
Correct |
19 ms |
31564 KB |
Output is correct |
15 |
Correct |
23 ms |
31572 KB |
Output is correct |
16 |
Correct |
19 ms |
31620 KB |
Output is correct |
17 |
Correct |
20 ms |
31620 KB |
Output is correct |
18 |
Correct |
19 ms |
31572 KB |
Output is correct |
19 |
Correct |
20 ms |
31684 KB |
Output is correct |
20 |
Correct |
20 ms |
31572 KB |
Output is correct |
21 |
Correct |
20 ms |
31644 KB |
Output is correct |
22 |
Correct |
20 ms |
31700 KB |
Output is correct |
23 |
Correct |
19 ms |
31636 KB |
Output is correct |
24 |
Correct |
21 ms |
31640 KB |
Output is correct |
25 |
Correct |
22 ms |
31632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
38572 KB |
Output is correct |
2 |
Correct |
93 ms |
39644 KB |
Output is correct |
3 |
Correct |
71 ms |
38324 KB |
Output is correct |
4 |
Correct |
80 ms |
39048 KB |
Output is correct |
5 |
Correct |
75 ms |
38248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
40384 KB |
Output is correct |
2 |
Correct |
77 ms |
40384 KB |
Output is correct |
3 |
Correct |
73 ms |
40164 KB |
Output is correct |
4 |
Correct |
78 ms |
40572 KB |
Output is correct |
5 |
Correct |
77 ms |
40156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
40492 KB |
Output is correct |
2 |
Correct |
81 ms |
40312 KB |
Output is correct |
3 |
Correct |
80 ms |
40180 KB |
Output is correct |
4 |
Correct |
86 ms |
40964 KB |
Output is correct |
5 |
Correct |
86 ms |
40540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
31616 KB |
Output is correct |
2 |
Correct |
19 ms |
31632 KB |
Output is correct |
3 |
Correct |
19 ms |
31568 KB |
Output is correct |
4 |
Correct |
19 ms |
31596 KB |
Output is correct |
5 |
Correct |
20 ms |
31548 KB |
Output is correct |
6 |
Correct |
20 ms |
31572 KB |
Output is correct |
7 |
Correct |
20 ms |
31580 KB |
Output is correct |
8 |
Correct |
19 ms |
31536 KB |
Output is correct |
9 |
Correct |
20 ms |
31504 KB |
Output is correct |
10 |
Correct |
19 ms |
31556 KB |
Output is correct |
11 |
Correct |
76 ms |
38572 KB |
Output is correct |
12 |
Correct |
93 ms |
39644 KB |
Output is correct |
13 |
Correct |
71 ms |
38324 KB |
Output is correct |
14 |
Correct |
80 ms |
39048 KB |
Output is correct |
15 |
Correct |
75 ms |
38248 KB |
Output is correct |
16 |
Correct |
71 ms |
38256 KB |
Output is correct |
17 |
Correct |
83 ms |
39584 KB |
Output is correct |
18 |
Correct |
88 ms |
39640 KB |
Output is correct |
19 |
Correct |
72 ms |
38140 KB |
Output is correct |
20 |
Correct |
86 ms |
39496 KB |
Output is correct |
21 |
Correct |
67 ms |
38212 KB |
Output is correct |
22 |
Correct |
85 ms |
39156 KB |
Output is correct |
23 |
Correct |
72 ms |
38728 KB |
Output is correct |
24 |
Correct |
84 ms |
39024 KB |
Output is correct |
25 |
Correct |
74 ms |
38468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
31616 KB |
Output is correct |
2 |
Correct |
19 ms |
31632 KB |
Output is correct |
3 |
Correct |
19 ms |
31568 KB |
Output is correct |
4 |
Correct |
19 ms |
31596 KB |
Output is correct |
5 |
Correct |
20 ms |
31548 KB |
Output is correct |
6 |
Correct |
20 ms |
31572 KB |
Output is correct |
7 |
Correct |
20 ms |
31580 KB |
Output is correct |
8 |
Correct |
19 ms |
31536 KB |
Output is correct |
9 |
Correct |
20 ms |
31504 KB |
Output is correct |
10 |
Correct |
19 ms |
31556 KB |
Output is correct |
11 |
Correct |
20 ms |
31572 KB |
Output is correct |
12 |
Correct |
19 ms |
31572 KB |
Output is correct |
13 |
Correct |
19 ms |
31620 KB |
Output is correct |
14 |
Correct |
19 ms |
31564 KB |
Output is correct |
15 |
Correct |
23 ms |
31572 KB |
Output is correct |
16 |
Correct |
19 ms |
31620 KB |
Output is correct |
17 |
Correct |
20 ms |
31620 KB |
Output is correct |
18 |
Correct |
19 ms |
31572 KB |
Output is correct |
19 |
Correct |
20 ms |
31684 KB |
Output is correct |
20 |
Correct |
20 ms |
31572 KB |
Output is correct |
21 |
Correct |
20 ms |
31644 KB |
Output is correct |
22 |
Correct |
20 ms |
31700 KB |
Output is correct |
23 |
Correct |
19 ms |
31636 KB |
Output is correct |
24 |
Correct |
21 ms |
31640 KB |
Output is correct |
25 |
Correct |
22 ms |
31632 KB |
Output is correct |
26 |
Correct |
76 ms |
38572 KB |
Output is correct |
27 |
Correct |
93 ms |
39644 KB |
Output is correct |
28 |
Correct |
71 ms |
38324 KB |
Output is correct |
29 |
Correct |
80 ms |
39048 KB |
Output is correct |
30 |
Correct |
75 ms |
38248 KB |
Output is correct |
31 |
Correct |
74 ms |
40384 KB |
Output is correct |
32 |
Correct |
77 ms |
40384 KB |
Output is correct |
33 |
Correct |
73 ms |
40164 KB |
Output is correct |
34 |
Correct |
78 ms |
40572 KB |
Output is correct |
35 |
Correct |
77 ms |
40156 KB |
Output is correct |
36 |
Correct |
80 ms |
40492 KB |
Output is correct |
37 |
Correct |
81 ms |
40312 KB |
Output is correct |
38 |
Correct |
80 ms |
40180 KB |
Output is correct |
39 |
Correct |
86 ms |
40964 KB |
Output is correct |
40 |
Correct |
86 ms |
40540 KB |
Output is correct |
41 |
Correct |
71 ms |
38256 KB |
Output is correct |
42 |
Correct |
83 ms |
39584 KB |
Output is correct |
43 |
Correct |
88 ms |
39640 KB |
Output is correct |
44 |
Correct |
72 ms |
38140 KB |
Output is correct |
45 |
Correct |
86 ms |
39496 KB |
Output is correct |
46 |
Correct |
67 ms |
38212 KB |
Output is correct |
47 |
Correct |
85 ms |
39156 KB |
Output is correct |
48 |
Correct |
72 ms |
38728 KB |
Output is correct |
49 |
Correct |
84 ms |
39024 KB |
Output is correct |
50 |
Correct |
74 ms |
38468 KB |
Output is correct |
51 |
Correct |
91 ms |
39308 KB |
Output is correct |
52 |
Correct |
109 ms |
39884 KB |
Output is correct |
53 |
Correct |
99 ms |
39456 KB |
Output is correct |
54 |
Correct |
105 ms |
39880 KB |
Output is correct |
55 |
Correct |
95 ms |
39476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
31616 KB |
Output is correct |
2 |
Correct |
19 ms |
31632 KB |
Output is correct |
3 |
Correct |
19 ms |
31568 KB |
Output is correct |
4 |
Correct |
19 ms |
31596 KB |
Output is correct |
5 |
Correct |
20 ms |
31548 KB |
Output is correct |
6 |
Correct |
20 ms |
31572 KB |
Output is correct |
7 |
Correct |
20 ms |
31580 KB |
Output is correct |
8 |
Correct |
19 ms |
31536 KB |
Output is correct |
9 |
Correct |
20 ms |
31504 KB |
Output is correct |
10 |
Correct |
19 ms |
31556 KB |
Output is correct |
11 |
Correct |
20 ms |
31572 KB |
Output is correct |
12 |
Correct |
19 ms |
31572 KB |
Output is correct |
13 |
Correct |
19 ms |
31620 KB |
Output is correct |
14 |
Correct |
19 ms |
31564 KB |
Output is correct |
15 |
Correct |
23 ms |
31572 KB |
Output is correct |
16 |
Correct |
19 ms |
31620 KB |
Output is correct |
17 |
Correct |
20 ms |
31620 KB |
Output is correct |
18 |
Correct |
19 ms |
31572 KB |
Output is correct |
19 |
Correct |
20 ms |
31684 KB |
Output is correct |
20 |
Correct |
20 ms |
31572 KB |
Output is correct |
21 |
Correct |
20 ms |
31644 KB |
Output is correct |
22 |
Correct |
20 ms |
31700 KB |
Output is correct |
23 |
Correct |
19 ms |
31636 KB |
Output is correct |
24 |
Correct |
21 ms |
31640 KB |
Output is correct |
25 |
Correct |
22 ms |
31632 KB |
Output is correct |
26 |
Correct |
76 ms |
38572 KB |
Output is correct |
27 |
Correct |
93 ms |
39644 KB |
Output is correct |
28 |
Correct |
71 ms |
38324 KB |
Output is correct |
29 |
Correct |
80 ms |
39048 KB |
Output is correct |
30 |
Correct |
75 ms |
38248 KB |
Output is correct |
31 |
Correct |
74 ms |
40384 KB |
Output is correct |
32 |
Correct |
77 ms |
40384 KB |
Output is correct |
33 |
Correct |
73 ms |
40164 KB |
Output is correct |
34 |
Correct |
78 ms |
40572 KB |
Output is correct |
35 |
Correct |
77 ms |
40156 KB |
Output is correct |
36 |
Correct |
80 ms |
40492 KB |
Output is correct |
37 |
Correct |
81 ms |
40312 KB |
Output is correct |
38 |
Correct |
80 ms |
40180 KB |
Output is correct |
39 |
Correct |
86 ms |
40964 KB |
Output is correct |
40 |
Correct |
86 ms |
40540 KB |
Output is correct |
41 |
Correct |
71 ms |
38256 KB |
Output is correct |
42 |
Correct |
83 ms |
39584 KB |
Output is correct |
43 |
Correct |
88 ms |
39640 KB |
Output is correct |
44 |
Correct |
72 ms |
38140 KB |
Output is correct |
45 |
Correct |
86 ms |
39496 KB |
Output is correct |
46 |
Correct |
67 ms |
38212 KB |
Output is correct |
47 |
Correct |
85 ms |
39156 KB |
Output is correct |
48 |
Correct |
72 ms |
38728 KB |
Output is correct |
49 |
Correct |
84 ms |
39024 KB |
Output is correct |
50 |
Correct |
74 ms |
38468 KB |
Output is correct |
51 |
Correct |
91 ms |
39308 KB |
Output is correct |
52 |
Correct |
109 ms |
39884 KB |
Output is correct |
53 |
Correct |
99 ms |
39456 KB |
Output is correct |
54 |
Correct |
105 ms |
39880 KB |
Output is correct |
55 |
Correct |
95 ms |
39476 KB |
Output is correct |
56 |
Execution timed out |
1055 ms |
96604 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |