//! The Leader Of Retards Bemola
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define sz(x) (ll) x.size()
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
ll Pow(ll a, ll b, ll md, ll ans = 1) {
for (; b; b >>= 1, a = a * a % md)
if (b & 1)
ans = ans * a % md;
return ans % md;
}
const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
ll ps[MAXN], L[MAXN], R[MAXN], A[MAXN], Q[MAXN], mark[MAXN], n, q;
map<pll, vector<ll>> mp; stack<ll> st;
ll C2(ll x) {
if (x < 0) return 0;
return x * (x - 1) / 2;
}
int main() {
scanf("%lld%lld", &n, &q);
for (ll i = 1; i <= n; i++) scanf("%lld", &A[i]);
A[0] = A[n + 1] = MOD;
st.push(0);
for (ll i = 1; i <= n; i++) {
while (A[st.top()] <= A[i]) st.pop();
L[i] = st.top() + 1;
st.push(i);
}
while (sz(st)) st.pop();
st.push(n + 1);
for (ll i = n; i; i--) {
while (A[st.top()] <= A[i]) st.pop();
R[i] = st.top() - 1;
st.push(i);
mp[{L[i], R[i]}].push_back(i);
}
for (auto &i : mp) {
sort(all(i.S));
ll res = C2(i.F.S - i.F.F + 2), prv = i.F.F, h = A[i.S[0]];
//printf("%lld %lld %lld\n", i.F.F, i.F.S, res);
i.S.push_back(i.F.S + 1);
for (ll j = 0; j < sz(i.S); j++) {
res -= C2((i.S)[j] - prv + 1);
//if (i.F.F == 1 && i.F.S == 2) printf("test %lld %lld\n", prv, i.S[j]);
prv = i.S[j] + 1;
}
//printf("%lld %lld %lld\n", i.F.F, i.F.S, res);
ps[h] += res;
}
partial_sum(ps, ps + MAXN, ps);
for (ll i = 1; i <= q; i++) {
ll x; scanf("%lld", &x);
printf("%lld\n", ps[x]);
}
return 0;
}
Compilation message
pilot.cpp: In function 'int main()':
pilot.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
32 | scanf("%lld%lld", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
pilot.cpp:33:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
33 | for (ll i = 1; i <= n; i++) scanf("%lld", &A[i]);
| ~~~~~^~~~~~~~~~~~~~~
pilot.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
64 | ll x; scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
6 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8172 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
6 ms |
8172 KB |
Output is correct |
6 |
Correct |
8 ms |
8172 KB |
Output is correct |
7 |
Correct |
6 ms |
8172 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
7 ms |
8300 KB |
Output is correct |
10 |
Correct |
6 ms |
8172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
6 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8172 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
6 ms |
8172 KB |
Output is correct |
6 |
Correct |
8 ms |
8172 KB |
Output is correct |
7 |
Correct |
6 ms |
8172 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
7 ms |
8300 KB |
Output is correct |
10 |
Correct |
6 ms |
8172 KB |
Output is correct |
11 |
Correct |
7 ms |
8260 KB |
Output is correct |
12 |
Correct |
6 ms |
8172 KB |
Output is correct |
13 |
Correct |
7 ms |
8300 KB |
Output is correct |
14 |
Correct |
6 ms |
8172 KB |
Output is correct |
15 |
Correct |
6 ms |
8172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
6 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8172 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
6 ms |
8172 KB |
Output is correct |
6 |
Correct |
8 ms |
8172 KB |
Output is correct |
7 |
Correct |
6 ms |
8172 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
7 ms |
8300 KB |
Output is correct |
10 |
Correct |
6 ms |
8172 KB |
Output is correct |
11 |
Correct |
7 ms |
8260 KB |
Output is correct |
12 |
Correct |
6 ms |
8172 KB |
Output is correct |
13 |
Correct |
7 ms |
8300 KB |
Output is correct |
14 |
Correct |
6 ms |
8172 KB |
Output is correct |
15 |
Correct |
6 ms |
8172 KB |
Output is correct |
16 |
Correct |
8 ms |
8172 KB |
Output is correct |
17 |
Correct |
7 ms |
8172 KB |
Output is correct |
18 |
Correct |
7 ms |
8172 KB |
Output is correct |
19 |
Correct |
8 ms |
8172 KB |
Output is correct |
20 |
Correct |
7 ms |
8212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
6 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8172 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
6 ms |
8172 KB |
Output is correct |
6 |
Correct |
8 ms |
8172 KB |
Output is correct |
7 |
Correct |
6 ms |
8172 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
7 ms |
8300 KB |
Output is correct |
10 |
Correct |
6 ms |
8172 KB |
Output is correct |
11 |
Correct |
7 ms |
8260 KB |
Output is correct |
12 |
Correct |
6 ms |
8172 KB |
Output is correct |
13 |
Correct |
7 ms |
8300 KB |
Output is correct |
14 |
Correct |
6 ms |
8172 KB |
Output is correct |
15 |
Correct |
6 ms |
8172 KB |
Output is correct |
16 |
Correct |
8 ms |
8172 KB |
Output is correct |
17 |
Correct |
7 ms |
8172 KB |
Output is correct |
18 |
Correct |
7 ms |
8172 KB |
Output is correct |
19 |
Correct |
8 ms |
8172 KB |
Output is correct |
20 |
Correct |
7 ms |
8212 KB |
Output is correct |
21 |
Correct |
7 ms |
8300 KB |
Output is correct |
22 |
Correct |
7 ms |
8300 KB |
Output is correct |
23 |
Correct |
7 ms |
8300 KB |
Output is correct |
24 |
Correct |
7 ms |
8556 KB |
Output is correct |
25 |
Correct |
8 ms |
8300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
20964 KB |
Output is correct |
2 |
Correct |
71 ms |
21220 KB |
Output is correct |
3 |
Correct |
55 ms |
20580 KB |
Output is correct |
4 |
Correct |
59 ms |
20196 KB |
Output is correct |
5 |
Correct |
61 ms |
20452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
22372 KB |
Output is correct |
2 |
Correct |
82 ms |
22372 KB |
Output is correct |
3 |
Correct |
81 ms |
22116 KB |
Output is correct |
4 |
Correct |
84 ms |
22756 KB |
Output is correct |
5 |
Correct |
87 ms |
22264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
22632 KB |
Output is correct |
2 |
Correct |
83 ms |
22240 KB |
Output is correct |
3 |
Correct |
88 ms |
21988 KB |
Output is correct |
4 |
Correct |
86 ms |
23268 KB |
Output is correct |
5 |
Correct |
86 ms |
22500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
6 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8172 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
6 ms |
8172 KB |
Output is correct |
6 |
Correct |
8 ms |
8172 KB |
Output is correct |
7 |
Correct |
6 ms |
8172 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
7 ms |
8300 KB |
Output is correct |
10 |
Correct |
6 ms |
8172 KB |
Output is correct |
11 |
Correct |
59 ms |
20964 KB |
Output is correct |
12 |
Correct |
71 ms |
21220 KB |
Output is correct |
13 |
Correct |
55 ms |
20580 KB |
Output is correct |
14 |
Correct |
59 ms |
20196 KB |
Output is correct |
15 |
Correct |
61 ms |
20452 KB |
Output is correct |
16 |
Correct |
62 ms |
20452 KB |
Output is correct |
17 |
Correct |
64 ms |
21348 KB |
Output is correct |
18 |
Correct |
64 ms |
21348 KB |
Output is correct |
19 |
Correct |
53 ms |
20324 KB |
Output is correct |
20 |
Correct |
60 ms |
20964 KB |
Output is correct |
21 |
Correct |
56 ms |
20324 KB |
Output is correct |
22 |
Correct |
60 ms |
20452 KB |
Output is correct |
23 |
Correct |
62 ms |
21348 KB |
Output is correct |
24 |
Correct |
62 ms |
20324 KB |
Output is correct |
25 |
Correct |
61 ms |
21092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
6 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8172 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
6 ms |
8172 KB |
Output is correct |
6 |
Correct |
8 ms |
8172 KB |
Output is correct |
7 |
Correct |
6 ms |
8172 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
7 ms |
8300 KB |
Output is correct |
10 |
Correct |
6 ms |
8172 KB |
Output is correct |
11 |
Correct |
7 ms |
8260 KB |
Output is correct |
12 |
Correct |
6 ms |
8172 KB |
Output is correct |
13 |
Correct |
7 ms |
8300 KB |
Output is correct |
14 |
Correct |
6 ms |
8172 KB |
Output is correct |
15 |
Correct |
6 ms |
8172 KB |
Output is correct |
16 |
Correct |
8 ms |
8172 KB |
Output is correct |
17 |
Correct |
7 ms |
8172 KB |
Output is correct |
18 |
Correct |
7 ms |
8172 KB |
Output is correct |
19 |
Correct |
8 ms |
8172 KB |
Output is correct |
20 |
Correct |
7 ms |
8212 KB |
Output is correct |
21 |
Correct |
7 ms |
8300 KB |
Output is correct |
22 |
Correct |
7 ms |
8300 KB |
Output is correct |
23 |
Correct |
7 ms |
8300 KB |
Output is correct |
24 |
Correct |
7 ms |
8556 KB |
Output is correct |
25 |
Correct |
8 ms |
8300 KB |
Output is correct |
26 |
Correct |
59 ms |
20964 KB |
Output is correct |
27 |
Correct |
71 ms |
21220 KB |
Output is correct |
28 |
Correct |
55 ms |
20580 KB |
Output is correct |
29 |
Correct |
59 ms |
20196 KB |
Output is correct |
30 |
Correct |
61 ms |
20452 KB |
Output is correct |
31 |
Correct |
81 ms |
22372 KB |
Output is correct |
32 |
Correct |
82 ms |
22372 KB |
Output is correct |
33 |
Correct |
81 ms |
22116 KB |
Output is correct |
34 |
Correct |
84 ms |
22756 KB |
Output is correct |
35 |
Correct |
87 ms |
22264 KB |
Output is correct |
36 |
Correct |
96 ms |
22632 KB |
Output is correct |
37 |
Correct |
83 ms |
22240 KB |
Output is correct |
38 |
Correct |
88 ms |
21988 KB |
Output is correct |
39 |
Correct |
86 ms |
23268 KB |
Output is correct |
40 |
Correct |
86 ms |
22500 KB |
Output is correct |
41 |
Correct |
62 ms |
20452 KB |
Output is correct |
42 |
Correct |
64 ms |
21348 KB |
Output is correct |
43 |
Correct |
64 ms |
21348 KB |
Output is correct |
44 |
Correct |
53 ms |
20324 KB |
Output is correct |
45 |
Correct |
60 ms |
20964 KB |
Output is correct |
46 |
Correct |
56 ms |
20324 KB |
Output is correct |
47 |
Correct |
60 ms |
20452 KB |
Output is correct |
48 |
Correct |
62 ms |
21348 KB |
Output is correct |
49 |
Correct |
62 ms |
20324 KB |
Output is correct |
50 |
Correct |
61 ms |
21092 KB |
Output is correct |
51 |
Correct |
88 ms |
21732 KB |
Output is correct |
52 |
Correct |
99 ms |
21352 KB |
Output is correct |
53 |
Correct |
93 ms |
21988 KB |
Output is correct |
54 |
Correct |
93 ms |
21348 KB |
Output is correct |
55 |
Correct |
100 ms |
22116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8172 KB |
Output is correct |
2 |
Correct |
6 ms |
8172 KB |
Output is correct |
3 |
Correct |
8 ms |
8172 KB |
Output is correct |
4 |
Correct |
7 ms |
8172 KB |
Output is correct |
5 |
Correct |
6 ms |
8172 KB |
Output is correct |
6 |
Correct |
8 ms |
8172 KB |
Output is correct |
7 |
Correct |
6 ms |
8172 KB |
Output is correct |
8 |
Correct |
6 ms |
8172 KB |
Output is correct |
9 |
Correct |
7 ms |
8300 KB |
Output is correct |
10 |
Correct |
6 ms |
8172 KB |
Output is correct |
11 |
Correct |
7 ms |
8260 KB |
Output is correct |
12 |
Correct |
6 ms |
8172 KB |
Output is correct |
13 |
Correct |
7 ms |
8300 KB |
Output is correct |
14 |
Correct |
6 ms |
8172 KB |
Output is correct |
15 |
Correct |
6 ms |
8172 KB |
Output is correct |
16 |
Correct |
8 ms |
8172 KB |
Output is correct |
17 |
Correct |
7 ms |
8172 KB |
Output is correct |
18 |
Correct |
7 ms |
8172 KB |
Output is correct |
19 |
Correct |
8 ms |
8172 KB |
Output is correct |
20 |
Correct |
7 ms |
8212 KB |
Output is correct |
21 |
Correct |
7 ms |
8300 KB |
Output is correct |
22 |
Correct |
7 ms |
8300 KB |
Output is correct |
23 |
Correct |
7 ms |
8300 KB |
Output is correct |
24 |
Correct |
7 ms |
8556 KB |
Output is correct |
25 |
Correct |
8 ms |
8300 KB |
Output is correct |
26 |
Correct |
59 ms |
20964 KB |
Output is correct |
27 |
Correct |
71 ms |
21220 KB |
Output is correct |
28 |
Correct |
55 ms |
20580 KB |
Output is correct |
29 |
Correct |
59 ms |
20196 KB |
Output is correct |
30 |
Correct |
61 ms |
20452 KB |
Output is correct |
31 |
Correct |
81 ms |
22372 KB |
Output is correct |
32 |
Correct |
82 ms |
22372 KB |
Output is correct |
33 |
Correct |
81 ms |
22116 KB |
Output is correct |
34 |
Correct |
84 ms |
22756 KB |
Output is correct |
35 |
Correct |
87 ms |
22264 KB |
Output is correct |
36 |
Correct |
96 ms |
22632 KB |
Output is correct |
37 |
Correct |
83 ms |
22240 KB |
Output is correct |
38 |
Correct |
88 ms |
21988 KB |
Output is correct |
39 |
Correct |
86 ms |
23268 KB |
Output is correct |
40 |
Correct |
86 ms |
22500 KB |
Output is correct |
41 |
Correct |
62 ms |
20452 KB |
Output is correct |
42 |
Correct |
64 ms |
21348 KB |
Output is correct |
43 |
Correct |
64 ms |
21348 KB |
Output is correct |
44 |
Correct |
53 ms |
20324 KB |
Output is correct |
45 |
Correct |
60 ms |
20964 KB |
Output is correct |
46 |
Correct |
56 ms |
20324 KB |
Output is correct |
47 |
Correct |
60 ms |
20452 KB |
Output is correct |
48 |
Correct |
62 ms |
21348 KB |
Output is correct |
49 |
Correct |
62 ms |
20324 KB |
Output is correct |
50 |
Correct |
61 ms |
21092 KB |
Output is correct |
51 |
Correct |
88 ms |
21732 KB |
Output is correct |
52 |
Correct |
99 ms |
21352 KB |
Output is correct |
53 |
Correct |
93 ms |
21988 KB |
Output is correct |
54 |
Correct |
93 ms |
21348 KB |
Output is correct |
55 |
Correct |
100 ms |
22116 KB |
Output is correct |
56 |
Correct |
980 ms |
140640 KB |
Output is correct |
57 |
Correct |
949 ms |
146656 KB |
Output is correct |
58 |
Correct |
896 ms |
135652 KB |
Output is correct |
59 |
Correct |
918 ms |
139224 KB |
Output is correct |
60 |
Correct |
982 ms |
146800 KB |
Output is correct |