//In The Name of Allah
#pragma GCC optimize("O2")
#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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
27 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
28 ms |
31596 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
24 ms |
31596 KB |
Output is correct |
7 |
Correct |
24 ms |
31596 KB |
Output is correct |
8 |
Correct |
25 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31736 KB |
Output is correct |
10 |
Correct |
24 ms |
31596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
27 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
28 ms |
31596 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
24 ms |
31596 KB |
Output is correct |
7 |
Correct |
24 ms |
31596 KB |
Output is correct |
8 |
Correct |
25 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31736 KB |
Output is correct |
10 |
Correct |
24 ms |
31596 KB |
Output is correct |
11 |
Correct |
24 ms |
31596 KB |
Output is correct |
12 |
Correct |
24 ms |
31596 KB |
Output is correct |
13 |
Correct |
23 ms |
31596 KB |
Output is correct |
14 |
Correct |
24 ms |
31596 KB |
Output is correct |
15 |
Correct |
27 ms |
31724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
27 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
28 ms |
31596 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
24 ms |
31596 KB |
Output is correct |
7 |
Correct |
24 ms |
31596 KB |
Output is correct |
8 |
Correct |
25 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31736 KB |
Output is correct |
10 |
Correct |
24 ms |
31596 KB |
Output is correct |
11 |
Correct |
24 ms |
31596 KB |
Output is correct |
12 |
Correct |
24 ms |
31596 KB |
Output is correct |
13 |
Correct |
23 ms |
31596 KB |
Output is correct |
14 |
Correct |
24 ms |
31596 KB |
Output is correct |
15 |
Correct |
27 ms |
31724 KB |
Output is correct |
16 |
Correct |
27 ms |
31852 KB |
Output is correct |
17 |
Correct |
25 ms |
31724 KB |
Output is correct |
18 |
Correct |
25 ms |
31596 KB |
Output is correct |
19 |
Correct |
26 ms |
31744 KB |
Output is correct |
20 |
Correct |
25 ms |
31596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
27 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
28 ms |
31596 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
24 ms |
31596 KB |
Output is correct |
7 |
Correct |
24 ms |
31596 KB |
Output is correct |
8 |
Correct |
25 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31736 KB |
Output is correct |
10 |
Correct |
24 ms |
31596 KB |
Output is correct |
11 |
Correct |
24 ms |
31596 KB |
Output is correct |
12 |
Correct |
24 ms |
31596 KB |
Output is correct |
13 |
Correct |
23 ms |
31596 KB |
Output is correct |
14 |
Correct |
24 ms |
31596 KB |
Output is correct |
15 |
Correct |
27 ms |
31724 KB |
Output is correct |
16 |
Correct |
27 ms |
31852 KB |
Output is correct |
17 |
Correct |
25 ms |
31724 KB |
Output is correct |
18 |
Correct |
25 ms |
31596 KB |
Output is correct |
19 |
Correct |
26 ms |
31744 KB |
Output is correct |
20 |
Correct |
25 ms |
31596 KB |
Output is correct |
21 |
Correct |
24 ms |
31852 KB |
Output is correct |
22 |
Correct |
25 ms |
31724 KB |
Output is correct |
23 |
Correct |
26 ms |
31724 KB |
Output is correct |
24 |
Correct |
25 ms |
31724 KB |
Output is correct |
25 |
Correct |
24 ms |
31744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
35180 KB |
Output is correct |
2 |
Correct |
126 ms |
36204 KB |
Output is correct |
3 |
Correct |
90 ms |
34924 KB |
Output is correct |
4 |
Correct |
100 ms |
35820 KB |
Output is correct |
5 |
Correct |
87 ms |
34924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
35948 KB |
Output is correct |
2 |
Correct |
73 ms |
35968 KB |
Output is correct |
3 |
Correct |
69 ms |
35948 KB |
Output is correct |
4 |
Correct |
70 ms |
36076 KB |
Output is correct |
5 |
Correct |
68 ms |
35820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
35948 KB |
Output is correct |
2 |
Correct |
75 ms |
35948 KB |
Output is correct |
3 |
Correct |
76 ms |
35820 KB |
Output is correct |
4 |
Correct |
76 ms |
36076 KB |
Output is correct |
5 |
Correct |
81 ms |
36036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
27 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
28 ms |
31596 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
24 ms |
31596 KB |
Output is correct |
7 |
Correct |
24 ms |
31596 KB |
Output is correct |
8 |
Correct |
25 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31736 KB |
Output is correct |
10 |
Correct |
24 ms |
31596 KB |
Output is correct |
11 |
Correct |
89 ms |
35180 KB |
Output is correct |
12 |
Correct |
126 ms |
36204 KB |
Output is correct |
13 |
Correct |
90 ms |
34924 KB |
Output is correct |
14 |
Correct |
100 ms |
35820 KB |
Output is correct |
15 |
Correct |
87 ms |
34924 KB |
Output is correct |
16 |
Correct |
91 ms |
34924 KB |
Output is correct |
17 |
Correct |
108 ms |
36076 KB |
Output is correct |
18 |
Correct |
109 ms |
36204 KB |
Output is correct |
19 |
Correct |
98 ms |
34924 KB |
Output is correct |
20 |
Correct |
112 ms |
36076 KB |
Output is correct |
21 |
Correct |
85 ms |
34924 KB |
Output is correct |
22 |
Correct |
102 ms |
35820 KB |
Output is correct |
23 |
Correct |
92 ms |
35308 KB |
Output is correct |
24 |
Correct |
106 ms |
35760 KB |
Output is correct |
25 |
Correct |
88 ms |
35052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
27 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
28 ms |
31596 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
24 ms |
31596 KB |
Output is correct |
7 |
Correct |
24 ms |
31596 KB |
Output is correct |
8 |
Correct |
25 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31736 KB |
Output is correct |
10 |
Correct |
24 ms |
31596 KB |
Output is correct |
11 |
Correct |
24 ms |
31596 KB |
Output is correct |
12 |
Correct |
24 ms |
31596 KB |
Output is correct |
13 |
Correct |
23 ms |
31596 KB |
Output is correct |
14 |
Correct |
24 ms |
31596 KB |
Output is correct |
15 |
Correct |
27 ms |
31724 KB |
Output is correct |
16 |
Correct |
27 ms |
31852 KB |
Output is correct |
17 |
Correct |
25 ms |
31724 KB |
Output is correct |
18 |
Correct |
25 ms |
31596 KB |
Output is correct |
19 |
Correct |
26 ms |
31744 KB |
Output is correct |
20 |
Correct |
25 ms |
31596 KB |
Output is correct |
21 |
Correct |
24 ms |
31852 KB |
Output is correct |
22 |
Correct |
25 ms |
31724 KB |
Output is correct |
23 |
Correct |
26 ms |
31724 KB |
Output is correct |
24 |
Correct |
25 ms |
31724 KB |
Output is correct |
25 |
Correct |
24 ms |
31744 KB |
Output is correct |
26 |
Correct |
89 ms |
35180 KB |
Output is correct |
27 |
Correct |
126 ms |
36204 KB |
Output is correct |
28 |
Correct |
90 ms |
34924 KB |
Output is correct |
29 |
Correct |
100 ms |
35820 KB |
Output is correct |
30 |
Correct |
87 ms |
34924 KB |
Output is correct |
31 |
Correct |
69 ms |
35948 KB |
Output is correct |
32 |
Correct |
73 ms |
35968 KB |
Output is correct |
33 |
Correct |
69 ms |
35948 KB |
Output is correct |
34 |
Correct |
70 ms |
36076 KB |
Output is correct |
35 |
Correct |
68 ms |
35820 KB |
Output is correct |
36 |
Correct |
74 ms |
35948 KB |
Output is correct |
37 |
Correct |
75 ms |
35948 KB |
Output is correct |
38 |
Correct |
76 ms |
35820 KB |
Output is correct |
39 |
Correct |
76 ms |
36076 KB |
Output is correct |
40 |
Correct |
81 ms |
36036 KB |
Output is correct |
41 |
Correct |
91 ms |
34924 KB |
Output is correct |
42 |
Correct |
108 ms |
36076 KB |
Output is correct |
43 |
Correct |
109 ms |
36204 KB |
Output is correct |
44 |
Correct |
98 ms |
34924 KB |
Output is correct |
45 |
Correct |
112 ms |
36076 KB |
Output is correct |
46 |
Correct |
85 ms |
34924 KB |
Output is correct |
47 |
Correct |
102 ms |
35820 KB |
Output is correct |
48 |
Correct |
92 ms |
35308 KB |
Output is correct |
49 |
Correct |
106 ms |
35760 KB |
Output is correct |
50 |
Correct |
88 ms |
35052 KB |
Output is correct |
51 |
Correct |
118 ms |
35948 KB |
Output is correct |
52 |
Correct |
133 ms |
36588 KB |
Output is correct |
53 |
Correct |
119 ms |
35948 KB |
Output is correct |
54 |
Correct |
131 ms |
36588 KB |
Output is correct |
55 |
Correct |
114 ms |
35948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31596 KB |
Output is correct |
2 |
Correct |
27 ms |
31596 KB |
Output is correct |
3 |
Correct |
25 ms |
31596 KB |
Output is correct |
4 |
Correct |
28 ms |
31596 KB |
Output is correct |
5 |
Correct |
25 ms |
31596 KB |
Output is correct |
6 |
Correct |
24 ms |
31596 KB |
Output is correct |
7 |
Correct |
24 ms |
31596 KB |
Output is correct |
8 |
Correct |
25 ms |
31596 KB |
Output is correct |
9 |
Correct |
25 ms |
31736 KB |
Output is correct |
10 |
Correct |
24 ms |
31596 KB |
Output is correct |
11 |
Correct |
24 ms |
31596 KB |
Output is correct |
12 |
Correct |
24 ms |
31596 KB |
Output is correct |
13 |
Correct |
23 ms |
31596 KB |
Output is correct |
14 |
Correct |
24 ms |
31596 KB |
Output is correct |
15 |
Correct |
27 ms |
31724 KB |
Output is correct |
16 |
Correct |
27 ms |
31852 KB |
Output is correct |
17 |
Correct |
25 ms |
31724 KB |
Output is correct |
18 |
Correct |
25 ms |
31596 KB |
Output is correct |
19 |
Correct |
26 ms |
31744 KB |
Output is correct |
20 |
Correct |
25 ms |
31596 KB |
Output is correct |
21 |
Correct |
24 ms |
31852 KB |
Output is correct |
22 |
Correct |
25 ms |
31724 KB |
Output is correct |
23 |
Correct |
26 ms |
31724 KB |
Output is correct |
24 |
Correct |
25 ms |
31724 KB |
Output is correct |
25 |
Correct |
24 ms |
31744 KB |
Output is correct |
26 |
Correct |
89 ms |
35180 KB |
Output is correct |
27 |
Correct |
126 ms |
36204 KB |
Output is correct |
28 |
Correct |
90 ms |
34924 KB |
Output is correct |
29 |
Correct |
100 ms |
35820 KB |
Output is correct |
30 |
Correct |
87 ms |
34924 KB |
Output is correct |
31 |
Correct |
69 ms |
35948 KB |
Output is correct |
32 |
Correct |
73 ms |
35968 KB |
Output is correct |
33 |
Correct |
69 ms |
35948 KB |
Output is correct |
34 |
Correct |
70 ms |
36076 KB |
Output is correct |
35 |
Correct |
68 ms |
35820 KB |
Output is correct |
36 |
Correct |
74 ms |
35948 KB |
Output is correct |
37 |
Correct |
75 ms |
35948 KB |
Output is correct |
38 |
Correct |
76 ms |
35820 KB |
Output is correct |
39 |
Correct |
76 ms |
36076 KB |
Output is correct |
40 |
Correct |
81 ms |
36036 KB |
Output is correct |
41 |
Correct |
91 ms |
34924 KB |
Output is correct |
42 |
Correct |
108 ms |
36076 KB |
Output is correct |
43 |
Correct |
109 ms |
36204 KB |
Output is correct |
44 |
Correct |
98 ms |
34924 KB |
Output is correct |
45 |
Correct |
112 ms |
36076 KB |
Output is correct |
46 |
Correct |
85 ms |
34924 KB |
Output is correct |
47 |
Correct |
102 ms |
35820 KB |
Output is correct |
48 |
Correct |
92 ms |
35308 KB |
Output is correct |
49 |
Correct |
106 ms |
35760 KB |
Output is correct |
50 |
Correct |
88 ms |
35052 KB |
Output is correct |
51 |
Correct |
118 ms |
35948 KB |
Output is correct |
52 |
Correct |
133 ms |
36588 KB |
Output is correct |
53 |
Correct |
119 ms |
35948 KB |
Output is correct |
54 |
Correct |
131 ms |
36588 KB |
Output is correct |
55 |
Correct |
114 ms |
35948 KB |
Output is correct |
56 |
Execution timed out |
1091 ms |
63000 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |