# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
861708 |
2023-10-16T16:57:39 Z |
wakandaaa |
Pilot (NOI19_pilot) |
C++17 |
|
240 ms |
41072 KB |
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1 << (x))
#define popcount __builtin_popcountll
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long r) {
return l + rd() % (r - l + 1);
}
const int N = 1e6 + 5;
const int mod = 1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int inf = 1e9; // INT_MAX;
const long long llinf = 1e18; // LLONG_MAX;
template<class X, class Y>
bool minimize(X &a, Y b) {
return a > b ? (a = b, true) : false;
}
template<class X, class Y>
bool maximize(X &a, Y b) {
return a < b ? (a = b, true) : false;
}
template<class X, class Y>
bool add(X &a, Y b) {
a += b;
while (a >= mod) a -= mod;
while (a < 0) a += mod;
return true;
}
int n, q;
int a[N];
int l[N], r[N];
long long d[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; ++i)
cin >> a[i];
stack<int> st;
for (int i = 1; i <= n; ++i) {
while (st.size() && a[st.top()] < a[i]) st.pop();
l[i] = st.size() ? st.top() : 0;
st.push(i);
}
st = stack<int>{};
for (int i = n; i >= 1; --i) {
while (st.size() && a[st.top()] <= a[i]) st.pop();
r[i] = st.size() ? st.top() : n + 1;
st.push(i);
}
for (int i = 1; i <= n; ++i) {
d[a[i]] += 1LL * (i - l[i]) * (r[i] - i);
}
for (int i = 1; i <= 1e6; ++i)
d[i] += d[i - 1];
while (q--) {
int x;
cin >> x;
cout << d[x] << '\n';
}
return 0;
}
/*
6 3
1 3 2 4 1 2
2 3 4
5
9
21
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12756 KB |
Output is correct |
4 |
Correct |
4 ms |
12888 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
4 ms |
12764 KB |
Output is correct |
7 |
Correct |
4 ms |
12888 KB |
Output is correct |
8 |
Correct |
4 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
4 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12756 KB |
Output is correct |
4 |
Correct |
4 ms |
12888 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
4 ms |
12764 KB |
Output is correct |
7 |
Correct |
4 ms |
12888 KB |
Output is correct |
8 |
Correct |
4 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
4 ms |
12892 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12892 KB |
Output is correct |
13 |
Correct |
4 ms |
12956 KB |
Output is correct |
14 |
Correct |
4 ms |
12888 KB |
Output is correct |
15 |
Correct |
4 ms |
12888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12756 KB |
Output is correct |
4 |
Correct |
4 ms |
12888 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
4 ms |
12764 KB |
Output is correct |
7 |
Correct |
4 ms |
12888 KB |
Output is correct |
8 |
Correct |
4 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
4 ms |
12892 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12892 KB |
Output is correct |
13 |
Correct |
4 ms |
12956 KB |
Output is correct |
14 |
Correct |
4 ms |
12888 KB |
Output is correct |
15 |
Correct |
4 ms |
12888 KB |
Output is correct |
16 |
Correct |
4 ms |
12892 KB |
Output is correct |
17 |
Correct |
4 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
4 ms |
12892 KB |
Output is correct |
20 |
Correct |
4 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12756 KB |
Output is correct |
4 |
Correct |
4 ms |
12888 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
4 ms |
12764 KB |
Output is correct |
7 |
Correct |
4 ms |
12888 KB |
Output is correct |
8 |
Correct |
4 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
4 ms |
12892 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12892 KB |
Output is correct |
13 |
Correct |
4 ms |
12956 KB |
Output is correct |
14 |
Correct |
4 ms |
12888 KB |
Output is correct |
15 |
Correct |
4 ms |
12888 KB |
Output is correct |
16 |
Correct |
4 ms |
12892 KB |
Output is correct |
17 |
Correct |
4 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
4 ms |
12892 KB |
Output is correct |
20 |
Correct |
4 ms |
12892 KB |
Output is correct |
21 |
Correct |
4 ms |
12892 KB |
Output is correct |
22 |
Correct |
4 ms |
12892 KB |
Output is correct |
23 |
Correct |
4 ms |
12892 KB |
Output is correct |
24 |
Correct |
4 ms |
12892 KB |
Output is correct |
25 |
Correct |
4 ms |
12888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
13328 KB |
Output is correct |
2 |
Correct |
12 ms |
13400 KB |
Output is correct |
3 |
Correct |
12 ms |
13280 KB |
Output is correct |
4 |
Correct |
11 ms |
13404 KB |
Output is correct |
5 |
Correct |
12 ms |
13408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
15196 KB |
Output is correct |
2 |
Correct |
24 ms |
15452 KB |
Output is correct |
3 |
Correct |
24 ms |
15452 KB |
Output is correct |
4 |
Correct |
24 ms |
15452 KB |
Output is correct |
5 |
Correct |
24 ms |
15188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
15448 KB |
Output is correct |
2 |
Correct |
27 ms |
15452 KB |
Output is correct |
3 |
Correct |
23 ms |
15452 KB |
Output is correct |
4 |
Correct |
27 ms |
15424 KB |
Output is correct |
5 |
Correct |
27 ms |
15452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12756 KB |
Output is correct |
4 |
Correct |
4 ms |
12888 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
4 ms |
12764 KB |
Output is correct |
7 |
Correct |
4 ms |
12888 KB |
Output is correct |
8 |
Correct |
4 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
4 ms |
12892 KB |
Output is correct |
11 |
Correct |
13 ms |
13328 KB |
Output is correct |
12 |
Correct |
12 ms |
13400 KB |
Output is correct |
13 |
Correct |
12 ms |
13280 KB |
Output is correct |
14 |
Correct |
11 ms |
13404 KB |
Output is correct |
15 |
Correct |
12 ms |
13408 KB |
Output is correct |
16 |
Correct |
12 ms |
13400 KB |
Output is correct |
17 |
Correct |
15 ms |
13404 KB |
Output is correct |
18 |
Correct |
12 ms |
13512 KB |
Output is correct |
19 |
Correct |
13 ms |
13512 KB |
Output is correct |
20 |
Correct |
12 ms |
13404 KB |
Output is correct |
21 |
Correct |
12 ms |
13404 KB |
Output is correct |
22 |
Correct |
14 ms |
13404 KB |
Output is correct |
23 |
Correct |
12 ms |
13404 KB |
Output is correct |
24 |
Correct |
11 ms |
13400 KB |
Output is correct |
25 |
Correct |
11 ms |
13404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12756 KB |
Output is correct |
4 |
Correct |
4 ms |
12888 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
4 ms |
12764 KB |
Output is correct |
7 |
Correct |
4 ms |
12888 KB |
Output is correct |
8 |
Correct |
4 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
4 ms |
12892 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12892 KB |
Output is correct |
13 |
Correct |
4 ms |
12956 KB |
Output is correct |
14 |
Correct |
4 ms |
12888 KB |
Output is correct |
15 |
Correct |
4 ms |
12888 KB |
Output is correct |
16 |
Correct |
4 ms |
12892 KB |
Output is correct |
17 |
Correct |
4 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
4 ms |
12892 KB |
Output is correct |
20 |
Correct |
4 ms |
12892 KB |
Output is correct |
21 |
Correct |
4 ms |
12892 KB |
Output is correct |
22 |
Correct |
4 ms |
12892 KB |
Output is correct |
23 |
Correct |
4 ms |
12892 KB |
Output is correct |
24 |
Correct |
4 ms |
12892 KB |
Output is correct |
25 |
Correct |
4 ms |
12888 KB |
Output is correct |
26 |
Correct |
13 ms |
13328 KB |
Output is correct |
27 |
Correct |
12 ms |
13400 KB |
Output is correct |
28 |
Correct |
12 ms |
13280 KB |
Output is correct |
29 |
Correct |
11 ms |
13404 KB |
Output is correct |
30 |
Correct |
12 ms |
13408 KB |
Output is correct |
31 |
Correct |
23 ms |
15196 KB |
Output is correct |
32 |
Correct |
24 ms |
15452 KB |
Output is correct |
33 |
Correct |
24 ms |
15452 KB |
Output is correct |
34 |
Correct |
24 ms |
15452 KB |
Output is correct |
35 |
Correct |
24 ms |
15188 KB |
Output is correct |
36 |
Correct |
23 ms |
15448 KB |
Output is correct |
37 |
Correct |
27 ms |
15452 KB |
Output is correct |
38 |
Correct |
23 ms |
15452 KB |
Output is correct |
39 |
Correct |
27 ms |
15424 KB |
Output is correct |
40 |
Correct |
27 ms |
15452 KB |
Output is correct |
41 |
Correct |
12 ms |
13400 KB |
Output is correct |
42 |
Correct |
15 ms |
13404 KB |
Output is correct |
43 |
Correct |
12 ms |
13512 KB |
Output is correct |
44 |
Correct |
13 ms |
13512 KB |
Output is correct |
45 |
Correct |
12 ms |
13404 KB |
Output is correct |
46 |
Correct |
12 ms |
13404 KB |
Output is correct |
47 |
Correct |
14 ms |
13404 KB |
Output is correct |
48 |
Correct |
12 ms |
13404 KB |
Output is correct |
49 |
Correct |
11 ms |
13400 KB |
Output is correct |
50 |
Correct |
11 ms |
13404 KB |
Output is correct |
51 |
Correct |
24 ms |
14940 KB |
Output is correct |
52 |
Correct |
25 ms |
14684 KB |
Output is correct |
53 |
Correct |
25 ms |
14684 KB |
Output is correct |
54 |
Correct |
27 ms |
14672 KB |
Output is correct |
55 |
Correct |
26 ms |
14672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
4 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12756 KB |
Output is correct |
4 |
Correct |
4 ms |
12888 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
4 ms |
12764 KB |
Output is correct |
7 |
Correct |
4 ms |
12888 KB |
Output is correct |
8 |
Correct |
4 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Correct |
4 ms |
12892 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
4 ms |
12892 KB |
Output is correct |
13 |
Correct |
4 ms |
12956 KB |
Output is correct |
14 |
Correct |
4 ms |
12888 KB |
Output is correct |
15 |
Correct |
4 ms |
12888 KB |
Output is correct |
16 |
Correct |
4 ms |
12892 KB |
Output is correct |
17 |
Correct |
4 ms |
12892 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
4 ms |
12892 KB |
Output is correct |
20 |
Correct |
4 ms |
12892 KB |
Output is correct |
21 |
Correct |
4 ms |
12892 KB |
Output is correct |
22 |
Correct |
4 ms |
12892 KB |
Output is correct |
23 |
Correct |
4 ms |
12892 KB |
Output is correct |
24 |
Correct |
4 ms |
12892 KB |
Output is correct |
25 |
Correct |
4 ms |
12888 KB |
Output is correct |
26 |
Correct |
13 ms |
13328 KB |
Output is correct |
27 |
Correct |
12 ms |
13400 KB |
Output is correct |
28 |
Correct |
12 ms |
13280 KB |
Output is correct |
29 |
Correct |
11 ms |
13404 KB |
Output is correct |
30 |
Correct |
12 ms |
13408 KB |
Output is correct |
31 |
Correct |
23 ms |
15196 KB |
Output is correct |
32 |
Correct |
24 ms |
15452 KB |
Output is correct |
33 |
Correct |
24 ms |
15452 KB |
Output is correct |
34 |
Correct |
24 ms |
15452 KB |
Output is correct |
35 |
Correct |
24 ms |
15188 KB |
Output is correct |
36 |
Correct |
23 ms |
15448 KB |
Output is correct |
37 |
Correct |
27 ms |
15452 KB |
Output is correct |
38 |
Correct |
23 ms |
15452 KB |
Output is correct |
39 |
Correct |
27 ms |
15424 KB |
Output is correct |
40 |
Correct |
27 ms |
15452 KB |
Output is correct |
41 |
Correct |
12 ms |
13400 KB |
Output is correct |
42 |
Correct |
15 ms |
13404 KB |
Output is correct |
43 |
Correct |
12 ms |
13512 KB |
Output is correct |
44 |
Correct |
13 ms |
13512 KB |
Output is correct |
45 |
Correct |
12 ms |
13404 KB |
Output is correct |
46 |
Correct |
12 ms |
13404 KB |
Output is correct |
47 |
Correct |
14 ms |
13404 KB |
Output is correct |
48 |
Correct |
12 ms |
13404 KB |
Output is correct |
49 |
Correct |
11 ms |
13400 KB |
Output is correct |
50 |
Correct |
11 ms |
13404 KB |
Output is correct |
51 |
Correct |
24 ms |
14940 KB |
Output is correct |
52 |
Correct |
25 ms |
14684 KB |
Output is correct |
53 |
Correct |
25 ms |
14684 KB |
Output is correct |
54 |
Correct |
27 ms |
14672 KB |
Output is correct |
55 |
Correct |
26 ms |
14672 KB |
Output is correct |
56 |
Correct |
240 ms |
40300 KB |
Output is correct |
57 |
Correct |
235 ms |
39764 KB |
Output is correct |
58 |
Correct |
222 ms |
38608 KB |
Output is correct |
59 |
Correct |
205 ms |
38996 KB |
Output is correct |
60 |
Correct |
230 ms |
41072 KB |
Output is correct |