//In The Name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 10;
int a[N]; ll res[N];
vector < int > pos[N];
set < pii > seg;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, q;
cin >> n >> q;
for (int i = 1; i <= n; i ++)
cin >> a[i], pos[a[i]].pb(i);
ll tot = n * (n + 1) / 2;
seg.insert(mp(n, 1));
for (int i = N - 10; i > 0; i --){
res[i] = tot;
for (int x : pos[i]){
auto itr = seg.lower_bound(mp(x, -inf));
ll l = itr -> Y, r = itr -> X;
tot -= (r - l + 1) * (r - l + 2) / 2;
tot += (x - l) * (x - l + 1) / 2;
tot += (r - x) * (r - x + 1) / 2;
seg.erase(itr);
if (l < x)
seg.insert(mp(x - 1, l));
if (x < r)
seg.insert(mp(r, x + 1));
}
}
for (int i = 0; i < q; i ++){
int x;
cin >> x;
cout << res[x] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
26 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
26 ms |
31744 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
25 ms |
31596 KB |
Output is correct |
7 |
Correct |
25 ms |
31596 KB |
Output is correct |
8 |
Correct |
26 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31724 KB |
Output is correct |
10 |
Correct |
26 ms |
31596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
26 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
26 ms |
31744 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
25 ms |
31596 KB |
Output is correct |
7 |
Correct |
25 ms |
31596 KB |
Output is correct |
8 |
Correct |
26 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31724 KB |
Output is correct |
10 |
Correct |
26 ms |
31596 KB |
Output is correct |
11 |
Correct |
25 ms |
31596 KB |
Output is correct |
12 |
Correct |
25 ms |
31616 KB |
Output is correct |
13 |
Correct |
26 ms |
31596 KB |
Output is correct |
14 |
Correct |
26 ms |
31744 KB |
Output is correct |
15 |
Correct |
25 ms |
31596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
26 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
26 ms |
31744 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
25 ms |
31596 KB |
Output is correct |
7 |
Correct |
25 ms |
31596 KB |
Output is correct |
8 |
Correct |
26 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31724 KB |
Output is correct |
10 |
Correct |
26 ms |
31596 KB |
Output is correct |
11 |
Correct |
25 ms |
31596 KB |
Output is correct |
12 |
Correct |
25 ms |
31616 KB |
Output is correct |
13 |
Correct |
26 ms |
31596 KB |
Output is correct |
14 |
Correct |
26 ms |
31744 KB |
Output is correct |
15 |
Correct |
25 ms |
31596 KB |
Output is correct |
16 |
Correct |
26 ms |
31724 KB |
Output is correct |
17 |
Correct |
26 ms |
31744 KB |
Output is correct |
18 |
Correct |
25 ms |
31596 KB |
Output is correct |
19 |
Correct |
26 ms |
31724 KB |
Output is correct |
20 |
Correct |
26 ms |
31724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
26 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
26 ms |
31744 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
25 ms |
31596 KB |
Output is correct |
7 |
Correct |
25 ms |
31596 KB |
Output is correct |
8 |
Correct |
26 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31724 KB |
Output is correct |
10 |
Correct |
26 ms |
31596 KB |
Output is correct |
11 |
Correct |
25 ms |
31596 KB |
Output is correct |
12 |
Correct |
25 ms |
31616 KB |
Output is correct |
13 |
Correct |
26 ms |
31596 KB |
Output is correct |
14 |
Correct |
26 ms |
31744 KB |
Output is correct |
15 |
Correct |
25 ms |
31596 KB |
Output is correct |
16 |
Correct |
26 ms |
31724 KB |
Output is correct |
17 |
Correct |
26 ms |
31744 KB |
Output is correct |
18 |
Correct |
25 ms |
31596 KB |
Output is correct |
19 |
Correct |
26 ms |
31724 KB |
Output is correct |
20 |
Correct |
26 ms |
31724 KB |
Output is correct |
21 |
Correct |
28 ms |
31852 KB |
Output is correct |
22 |
Correct |
27 ms |
31724 KB |
Output is correct |
23 |
Correct |
26 ms |
31724 KB |
Output is correct |
24 |
Correct |
30 ms |
31724 KB |
Output is correct |
25 |
Correct |
26 ms |
31736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
35692 KB |
Output is correct |
2 |
Correct |
110 ms |
36844 KB |
Output is correct |
3 |
Correct |
94 ms |
35624 KB |
Output is correct |
4 |
Correct |
100 ms |
36332 KB |
Output is correct |
5 |
Correct |
87 ms |
35564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
37100 KB |
Output is correct |
2 |
Correct |
77 ms |
37176 KB |
Output is correct |
3 |
Correct |
70 ms |
36972 KB |
Output is correct |
4 |
Correct |
71 ms |
37228 KB |
Output is correct |
5 |
Correct |
70 ms |
37044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
37356 KB |
Output is correct |
2 |
Correct |
76 ms |
37100 KB |
Output is correct |
3 |
Correct |
79 ms |
37100 KB |
Output is correct |
4 |
Correct |
90 ms |
37488 KB |
Output is correct |
5 |
Correct |
83 ms |
37484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
26 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
26 ms |
31744 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
25 ms |
31596 KB |
Output is correct |
7 |
Correct |
25 ms |
31596 KB |
Output is correct |
8 |
Correct |
26 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31724 KB |
Output is correct |
10 |
Correct |
26 ms |
31596 KB |
Output is correct |
11 |
Correct |
90 ms |
35692 KB |
Output is correct |
12 |
Correct |
110 ms |
36844 KB |
Output is correct |
13 |
Correct |
94 ms |
35624 KB |
Output is correct |
14 |
Correct |
100 ms |
36332 KB |
Output is correct |
15 |
Correct |
87 ms |
35564 KB |
Output is correct |
16 |
Correct |
88 ms |
35564 KB |
Output is correct |
17 |
Correct |
111 ms |
36716 KB |
Output is correct |
18 |
Correct |
111 ms |
36872 KB |
Output is correct |
19 |
Correct |
92 ms |
35392 KB |
Output is correct |
20 |
Correct |
107 ms |
36716 KB |
Output is correct |
21 |
Correct |
94 ms |
35436 KB |
Output is correct |
22 |
Correct |
105 ms |
36588 KB |
Output is correct |
23 |
Correct |
113 ms |
35820 KB |
Output is correct |
24 |
Correct |
104 ms |
36460 KB |
Output is correct |
25 |
Correct |
106 ms |
35692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
26 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
26 ms |
31744 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
25 ms |
31596 KB |
Output is correct |
7 |
Correct |
25 ms |
31596 KB |
Output is correct |
8 |
Correct |
26 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31724 KB |
Output is correct |
10 |
Correct |
26 ms |
31596 KB |
Output is correct |
11 |
Correct |
25 ms |
31596 KB |
Output is correct |
12 |
Correct |
25 ms |
31616 KB |
Output is correct |
13 |
Correct |
26 ms |
31596 KB |
Output is correct |
14 |
Correct |
26 ms |
31744 KB |
Output is correct |
15 |
Correct |
25 ms |
31596 KB |
Output is correct |
16 |
Correct |
26 ms |
31724 KB |
Output is correct |
17 |
Correct |
26 ms |
31744 KB |
Output is correct |
18 |
Correct |
25 ms |
31596 KB |
Output is correct |
19 |
Correct |
26 ms |
31724 KB |
Output is correct |
20 |
Correct |
26 ms |
31724 KB |
Output is correct |
21 |
Correct |
28 ms |
31852 KB |
Output is correct |
22 |
Correct |
27 ms |
31724 KB |
Output is correct |
23 |
Correct |
26 ms |
31724 KB |
Output is correct |
24 |
Correct |
30 ms |
31724 KB |
Output is correct |
25 |
Correct |
26 ms |
31736 KB |
Output is correct |
26 |
Correct |
90 ms |
35692 KB |
Output is correct |
27 |
Correct |
110 ms |
36844 KB |
Output is correct |
28 |
Correct |
94 ms |
35624 KB |
Output is correct |
29 |
Correct |
100 ms |
36332 KB |
Output is correct |
30 |
Correct |
87 ms |
35564 KB |
Output is correct |
31 |
Correct |
70 ms |
37100 KB |
Output is correct |
32 |
Correct |
77 ms |
37176 KB |
Output is correct |
33 |
Correct |
70 ms |
36972 KB |
Output is correct |
34 |
Correct |
71 ms |
37228 KB |
Output is correct |
35 |
Correct |
70 ms |
37044 KB |
Output is correct |
36 |
Correct |
75 ms |
37356 KB |
Output is correct |
37 |
Correct |
76 ms |
37100 KB |
Output is correct |
38 |
Correct |
79 ms |
37100 KB |
Output is correct |
39 |
Correct |
90 ms |
37488 KB |
Output is correct |
40 |
Correct |
83 ms |
37484 KB |
Output is correct |
41 |
Correct |
88 ms |
35564 KB |
Output is correct |
42 |
Correct |
111 ms |
36716 KB |
Output is correct |
43 |
Correct |
111 ms |
36872 KB |
Output is correct |
44 |
Correct |
92 ms |
35392 KB |
Output is correct |
45 |
Correct |
107 ms |
36716 KB |
Output is correct |
46 |
Correct |
94 ms |
35436 KB |
Output is correct |
47 |
Correct |
105 ms |
36588 KB |
Output is correct |
48 |
Correct |
113 ms |
35820 KB |
Output is correct |
49 |
Correct |
104 ms |
36460 KB |
Output is correct |
50 |
Correct |
106 ms |
35692 KB |
Output is correct |
51 |
Correct |
117 ms |
37100 KB |
Output is correct |
52 |
Correct |
139 ms |
37868 KB |
Output is correct |
53 |
Correct |
137 ms |
37100 KB |
Output is correct |
54 |
Correct |
134 ms |
37868 KB |
Output is correct |
55 |
Correct |
117 ms |
37100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
26 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
26 ms |
31744 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
25 ms |
31596 KB |
Output is correct |
7 |
Correct |
25 ms |
31596 KB |
Output is correct |
8 |
Correct |
26 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31724 KB |
Output is correct |
10 |
Correct |
26 ms |
31596 KB |
Output is correct |
11 |
Correct |
25 ms |
31596 KB |
Output is correct |
12 |
Correct |
25 ms |
31616 KB |
Output is correct |
13 |
Correct |
26 ms |
31596 KB |
Output is correct |
14 |
Correct |
26 ms |
31744 KB |
Output is correct |
15 |
Correct |
25 ms |
31596 KB |
Output is correct |
16 |
Correct |
26 ms |
31724 KB |
Output is correct |
17 |
Correct |
26 ms |
31744 KB |
Output is correct |
18 |
Correct |
25 ms |
31596 KB |
Output is correct |
19 |
Correct |
26 ms |
31724 KB |
Output is correct |
20 |
Correct |
26 ms |
31724 KB |
Output is correct |
21 |
Correct |
28 ms |
31852 KB |
Output is correct |
22 |
Correct |
27 ms |
31724 KB |
Output is correct |
23 |
Correct |
26 ms |
31724 KB |
Output is correct |
24 |
Correct |
30 ms |
31724 KB |
Output is correct |
25 |
Correct |
26 ms |
31736 KB |
Output is correct |
26 |
Correct |
90 ms |
35692 KB |
Output is correct |
27 |
Correct |
110 ms |
36844 KB |
Output is correct |
28 |
Correct |
94 ms |
35624 KB |
Output is correct |
29 |
Correct |
100 ms |
36332 KB |
Output is correct |
30 |
Correct |
87 ms |
35564 KB |
Output is correct |
31 |
Correct |
70 ms |
37100 KB |
Output is correct |
32 |
Correct |
77 ms |
37176 KB |
Output is correct |
33 |
Correct |
70 ms |
36972 KB |
Output is correct |
34 |
Correct |
71 ms |
37228 KB |
Output is correct |
35 |
Correct |
70 ms |
37044 KB |
Output is correct |
36 |
Correct |
75 ms |
37356 KB |
Output is correct |
37 |
Correct |
76 ms |
37100 KB |
Output is correct |
38 |
Correct |
79 ms |
37100 KB |
Output is correct |
39 |
Correct |
90 ms |
37488 KB |
Output is correct |
40 |
Correct |
83 ms |
37484 KB |
Output is correct |
41 |
Correct |
88 ms |
35564 KB |
Output is correct |
42 |
Correct |
111 ms |
36716 KB |
Output is correct |
43 |
Correct |
111 ms |
36872 KB |
Output is correct |
44 |
Correct |
92 ms |
35392 KB |
Output is correct |
45 |
Correct |
107 ms |
36716 KB |
Output is correct |
46 |
Correct |
94 ms |
35436 KB |
Output is correct |
47 |
Correct |
105 ms |
36588 KB |
Output is correct |
48 |
Correct |
113 ms |
35820 KB |
Output is correct |
49 |
Correct |
104 ms |
36460 KB |
Output is correct |
50 |
Correct |
106 ms |
35692 KB |
Output is correct |
51 |
Correct |
117 ms |
37100 KB |
Output is correct |
52 |
Correct |
139 ms |
37868 KB |
Output is correct |
53 |
Correct |
137 ms |
37100 KB |
Output is correct |
54 |
Correct |
134 ms |
37868 KB |
Output is correct |
55 |
Correct |
117 ms |
37100 KB |
Output is correct |
56 |
Execution timed out |
1102 ms |
69448 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |