# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330773 | 2020-11-26T14:24:24 Z | ThaiBaHung | Pilot (NOI19_pilot) | C++14 | 1000 ms | 122696 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 3; int n, q; int a[N]; int qu[N]; long long L[N], R[N]; stack < int > st; vector < int > num[N]; vector < int > pos[N]; long long ans[N]; vector < int > cur; int ma = 0; int main() { //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("pilot.in","r",stdin); freopen("pilot.out","w",stdout); cin >> n >> q; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); num[a[i]].push_back(i); } for (int i = 1; i <= q; i++) scanf("%d", &qu[i]), ma = max(ma, qu[i]), pos[qu[i]].push_back(i); st.push(0); a[0] = 1e9 + 7; for (int i = 1; i <= n; i++) { while (st.size() && a[i] >= a[st.top()]) st.pop(); L[i] = st.top() + 1; st.push(i); } while (st.size()) st.pop(); a[n + 1] = 1e9 + 7; st.push(n + 1); for (int i = n; i >= 1; i--) { while (st.size() && a[i] > a[st.top()]) st.pop(); R[i] = st.top() - 1; st.push(i); } long long res = 0; for (int i = 1; i <= ma; i++) { for (int u : num[i]) cur.push_back(u); if (pos[i].size()) { for (int u : cur) { long long lo = u - L[u] + 1; long long hi = R[u] - u + 1; res += hi * lo; } for (int vt : pos[i]) ans[vt] = res; cur.clear(); } } for (int i = 1; i <= q; i++) cout << ans[i] << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | Output is correct |
2 | Correct | 34 ms | 47340 KB | Output is correct |
3 | Correct | 35 ms | 47340 KB | Output is correct |
4 | Correct | 32 ms | 47340 KB | Output is correct |
5 | Correct | 34 ms | 47340 KB | Output is correct |
6 | Correct | 33 ms | 47340 KB | Output is correct |
7 | Correct | 36 ms | 47340 KB | Output is correct |
8 | Correct | 34 ms | 47340 KB | Output is correct |
9 | Correct | 37 ms | 47468 KB | Output is correct |
10 | Correct | 33 ms | 47340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | Output is correct |
2 | Correct | 34 ms | 47340 KB | Output is correct |
3 | Correct | 35 ms | 47340 KB | Output is correct |
4 | Correct | 32 ms | 47340 KB | Output is correct |
5 | Correct | 34 ms | 47340 KB | Output is correct |
6 | Correct | 33 ms | 47340 KB | Output is correct |
7 | Correct | 36 ms | 47340 KB | Output is correct |
8 | Correct | 34 ms | 47340 KB | Output is correct |
9 | Correct | 37 ms | 47468 KB | Output is correct |
10 | Correct | 33 ms | 47340 KB | Output is correct |
11 | Correct | 36 ms | 47340 KB | Output is correct |
12 | Correct | 37 ms | 47340 KB | Output is correct |
13 | Correct | 36 ms | 47340 KB | Output is correct |
14 | Correct | 37 ms | 47340 KB | Output is correct |
15 | Correct | 35 ms | 47340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | Output is correct |
2 | Correct | 34 ms | 47340 KB | Output is correct |
3 | Correct | 35 ms | 47340 KB | Output is correct |
4 | Correct | 32 ms | 47340 KB | Output is correct |
5 | Correct | 34 ms | 47340 KB | Output is correct |
6 | Correct | 33 ms | 47340 KB | Output is correct |
7 | Correct | 36 ms | 47340 KB | Output is correct |
8 | Correct | 34 ms | 47340 KB | Output is correct |
9 | Correct | 37 ms | 47468 KB | Output is correct |
10 | Correct | 33 ms | 47340 KB | Output is correct |
11 | Correct | 36 ms | 47340 KB | Output is correct |
12 | Correct | 37 ms | 47340 KB | Output is correct |
13 | Correct | 36 ms | 47340 KB | Output is correct |
14 | Correct | 37 ms | 47340 KB | Output is correct |
15 | Correct | 35 ms | 47340 KB | Output is correct |
16 | Correct | 36 ms | 47360 KB | Output is correct |
17 | Correct | 38 ms | 47340 KB | Output is correct |
18 | Correct | 38 ms | 47340 KB | Output is correct |
19 | Correct | 36 ms | 47340 KB | Output is correct |
20 | Correct | 37 ms | 47468 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | Output is correct |
2 | Correct | 34 ms | 47340 KB | Output is correct |
3 | Correct | 35 ms | 47340 KB | Output is correct |
4 | Correct | 32 ms | 47340 KB | Output is correct |
5 | Correct | 34 ms | 47340 KB | Output is correct |
6 | Correct | 33 ms | 47340 KB | Output is correct |
7 | Correct | 36 ms | 47340 KB | Output is correct |
8 | Correct | 34 ms | 47340 KB | Output is correct |
9 | Correct | 37 ms | 47468 KB | Output is correct |
10 | Correct | 33 ms | 47340 KB | Output is correct |
11 | Correct | 36 ms | 47340 KB | Output is correct |
12 | Correct | 37 ms | 47340 KB | Output is correct |
13 | Correct | 36 ms | 47340 KB | Output is correct |
14 | Correct | 37 ms | 47340 KB | Output is correct |
15 | Correct | 35 ms | 47340 KB | Output is correct |
16 | Correct | 36 ms | 47360 KB | Output is correct |
17 | Correct | 38 ms | 47340 KB | Output is correct |
18 | Correct | 38 ms | 47340 KB | Output is correct |
19 | Correct | 36 ms | 47340 KB | Output is correct |
20 | Correct | 37 ms | 47468 KB | Output is correct |
21 | Correct | 37 ms | 47468 KB | Output is correct |
22 | Correct | 38 ms | 47488 KB | Output is correct |
23 | Correct | 36 ms | 47468 KB | Output is correct |
24 | Correct | 38 ms | 47468 KB | Output is correct |
25 | Correct | 37 ms | 47468 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 51824 KB | Output is correct |
2 | Correct | 85 ms | 52840 KB | Output is correct |
3 | Correct | 70 ms | 51688 KB | Output is correct |
4 | Correct | 80 ms | 52584 KB | Output is correct |
5 | Correct | 72 ms | 51692 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 113 ms | 57068 KB | Output is correct |
2 | Correct | 120 ms | 57196 KB | Output is correct |
3 | Correct | 116 ms | 57068 KB | Output is correct |
4 | Correct | 113 ms | 57324 KB | Output is correct |
5 | Correct | 116 ms | 56940 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 121 ms | 57196 KB | Output is correct |
2 | Correct | 123 ms | 57324 KB | Output is correct |
3 | Correct | 122 ms | 57196 KB | Output is correct |
4 | Correct | 123 ms | 57452 KB | Output is correct |
5 | Correct | 130 ms | 57452 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | Output is correct |
2 | Correct | 34 ms | 47340 KB | Output is correct |
3 | Correct | 35 ms | 47340 KB | Output is correct |
4 | Correct | 32 ms | 47340 KB | Output is correct |
5 | Correct | 34 ms | 47340 KB | Output is correct |
6 | Correct | 33 ms | 47340 KB | Output is correct |
7 | Correct | 36 ms | 47340 KB | Output is correct |
8 | Correct | 34 ms | 47340 KB | Output is correct |
9 | Correct | 37 ms | 47468 KB | Output is correct |
10 | Correct | 33 ms | 47340 KB | Output is correct |
11 | Correct | 69 ms | 51824 KB | Output is correct |
12 | Correct | 85 ms | 52840 KB | Output is correct |
13 | Correct | 70 ms | 51688 KB | Output is correct |
14 | Correct | 80 ms | 52584 KB | Output is correct |
15 | Correct | 72 ms | 51692 KB | Output is correct |
16 | Correct | 64 ms | 51312 KB | Output is correct |
17 | Correct | 76 ms | 52588 KB | Output is correct |
18 | Correct | 74 ms | 52460 KB | Output is correct |
19 | Correct | 64 ms | 51052 KB | Output is correct |
20 | Correct | 75 ms | 52460 KB | Output is correct |
21 | Correct | 63 ms | 51568 KB | Output is correct |
22 | Correct | 74 ms | 52332 KB | Output is correct |
23 | Correct | 64 ms | 51460 KB | Output is correct |
24 | Correct | 71 ms | 52076 KB | Output is correct |
25 | Correct | 64 ms | 51436 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | Output is correct |
2 | Correct | 34 ms | 47340 KB | Output is correct |
3 | Correct | 35 ms | 47340 KB | Output is correct |
4 | Correct | 32 ms | 47340 KB | Output is correct |
5 | Correct | 34 ms | 47340 KB | Output is correct |
6 | Correct | 33 ms | 47340 KB | Output is correct |
7 | Correct | 36 ms | 47340 KB | Output is correct |
8 | Correct | 34 ms | 47340 KB | Output is correct |
9 | Correct | 37 ms | 47468 KB | Output is correct |
10 | Correct | 33 ms | 47340 KB | Output is correct |
11 | Correct | 36 ms | 47340 KB | Output is correct |
12 | Correct | 37 ms | 47340 KB | Output is correct |
13 | Correct | 36 ms | 47340 KB | Output is correct |
14 | Correct | 37 ms | 47340 KB | Output is correct |
15 | Correct | 35 ms | 47340 KB | Output is correct |
16 | Correct | 36 ms | 47360 KB | Output is correct |
17 | Correct | 38 ms | 47340 KB | Output is correct |
18 | Correct | 38 ms | 47340 KB | Output is correct |
19 | Correct | 36 ms | 47340 KB | Output is correct |
20 | Correct | 37 ms | 47468 KB | Output is correct |
21 | Correct | 37 ms | 47468 KB | Output is correct |
22 | Correct | 38 ms | 47488 KB | Output is correct |
23 | Correct | 36 ms | 47468 KB | Output is correct |
24 | Correct | 38 ms | 47468 KB | Output is correct |
25 | Correct | 37 ms | 47468 KB | Output is correct |
26 | Correct | 69 ms | 51824 KB | Output is correct |
27 | Correct | 85 ms | 52840 KB | Output is correct |
28 | Correct | 70 ms | 51688 KB | Output is correct |
29 | Correct | 80 ms | 52584 KB | Output is correct |
30 | Correct | 72 ms | 51692 KB | Output is correct |
31 | Correct | 113 ms | 57068 KB | Output is correct |
32 | Correct | 120 ms | 57196 KB | Output is correct |
33 | Correct | 116 ms | 57068 KB | Output is correct |
34 | Correct | 113 ms | 57324 KB | Output is correct |
35 | Correct | 116 ms | 56940 KB | Output is correct |
36 | Correct | 121 ms | 57196 KB | Output is correct |
37 | Correct | 123 ms | 57324 KB | Output is correct |
38 | Correct | 122 ms | 57196 KB | Output is correct |
39 | Correct | 123 ms | 57452 KB | Output is correct |
40 | Correct | 130 ms | 57452 KB | Output is correct |
41 | Correct | 64 ms | 51312 KB | Output is correct |
42 | Correct | 76 ms | 52588 KB | Output is correct |
43 | Correct | 74 ms | 52460 KB | Output is correct |
44 | Correct | 64 ms | 51052 KB | Output is correct |
45 | Correct | 75 ms | 52460 KB | Output is correct |
46 | Correct | 63 ms | 51568 KB | Output is correct |
47 | Correct | 74 ms | 52332 KB | Output is correct |
48 | Correct | 64 ms | 51460 KB | Output is correct |
49 | Correct | 71 ms | 52076 KB | Output is correct |
50 | Correct | 64 ms | 51436 KB | Output is correct |
51 | Correct | 126 ms | 55532 KB | Output is correct |
52 | Correct | 142 ms | 56556 KB | Output is correct |
53 | Correct | 135 ms | 55660 KB | Output is correct |
54 | Correct | 140 ms | 56428 KB | Output is correct |
55 | Correct | 123 ms | 55532 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | Output is correct |
2 | Correct | 34 ms | 47340 KB | Output is correct |
3 | Correct | 35 ms | 47340 KB | Output is correct |
4 | Correct | 32 ms | 47340 KB | Output is correct |
5 | Correct | 34 ms | 47340 KB | Output is correct |
6 | Correct | 33 ms | 47340 KB | Output is correct |
7 | Correct | 36 ms | 47340 KB | Output is correct |
8 | Correct | 34 ms | 47340 KB | Output is correct |
9 | Correct | 37 ms | 47468 KB | Output is correct |
10 | Correct | 33 ms | 47340 KB | Output is correct |
11 | Correct | 36 ms | 47340 KB | Output is correct |
12 | Correct | 37 ms | 47340 KB | Output is correct |
13 | Correct | 36 ms | 47340 KB | Output is correct |
14 | Correct | 37 ms | 47340 KB | Output is correct |
15 | Correct | 35 ms | 47340 KB | Output is correct |
16 | Correct | 36 ms | 47360 KB | Output is correct |
17 | Correct | 38 ms | 47340 KB | Output is correct |
18 | Correct | 38 ms | 47340 KB | Output is correct |
19 | Correct | 36 ms | 47340 KB | Output is correct |
20 | Correct | 37 ms | 47468 KB | Output is correct |
21 | Correct | 37 ms | 47468 KB | Output is correct |
22 | Correct | 38 ms | 47488 KB | Output is correct |
23 | Correct | 36 ms | 47468 KB | Output is correct |
24 | Correct | 38 ms | 47468 KB | Output is correct |
25 | Correct | 37 ms | 47468 KB | Output is correct |
26 | Correct | 69 ms | 51824 KB | Output is correct |
27 | Correct | 85 ms | 52840 KB | Output is correct |
28 | Correct | 70 ms | 51688 KB | Output is correct |
29 | Correct | 80 ms | 52584 KB | Output is correct |
30 | Correct | 72 ms | 51692 KB | Output is correct |
31 | Correct | 113 ms | 57068 KB | Output is correct |
32 | Correct | 120 ms | 57196 KB | Output is correct |
33 | Correct | 116 ms | 57068 KB | Output is correct |
34 | Correct | 113 ms | 57324 KB | Output is correct |
35 | Correct | 116 ms | 56940 KB | Output is correct |
36 | Correct | 121 ms | 57196 KB | Output is correct |
37 | Correct | 123 ms | 57324 KB | Output is correct |
38 | Correct | 122 ms | 57196 KB | Output is correct |
39 | Correct | 123 ms | 57452 KB | Output is correct |
40 | Correct | 130 ms | 57452 KB | Output is correct |
41 | Correct | 64 ms | 51312 KB | Output is correct |
42 | Correct | 76 ms | 52588 KB | Output is correct |
43 | Correct | 74 ms | 52460 KB | Output is correct |
44 | Correct | 64 ms | 51052 KB | Output is correct |
45 | Correct | 75 ms | 52460 KB | Output is correct |
46 | Correct | 63 ms | 51568 KB | Output is correct |
47 | Correct | 74 ms | 52332 KB | Output is correct |
48 | Correct | 64 ms | 51460 KB | Output is correct |
49 | Correct | 71 ms | 52076 KB | Output is correct |
50 | Correct | 64 ms | 51436 KB | Output is correct |
51 | Correct | 126 ms | 55532 KB | Output is correct |
52 | Correct | 142 ms | 56556 KB | Output is correct |
53 | Correct | 135 ms | 55660 KB | Output is correct |
54 | Correct | 140 ms | 56428 KB | Output is correct |
55 | Correct | 123 ms | 55532 KB | Output is correct |
56 | Execution timed out | 1062 ms | 122696 KB | Time limit exceeded |
57 | Halted | 0 ms | 0 KB | - |