Submission #330771

# Submission time Handle Problem Language Result Execution time Memory
330771 2020-11-26T14:20:08 Z ThaiBaHung Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 135592 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++)
    {
        cin >> a[i];
        num[a[i]].push_back(i);
    }

    for (int i = 1; i <= q; i++)
        cin >> 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';
}
# Verdict Execution time Memory Grader output
1 Correct 37 ms 47340 KB Output is correct
2 Correct 39 ms 47340 KB Output is correct
3 Correct 34 ms 47340 KB Output is correct
4 Correct 33 ms 47340 KB Output is correct
5 Correct 38 ms 47340 KB Output is correct
6 Correct 33 ms 47340 KB Output is correct
7 Correct 39 ms 47340 KB Output is correct
8 Correct 33 ms 47340 KB Output is correct
9 Correct 36 ms 47340 KB Output is correct
10 Correct 34 ms 47400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 47340 KB Output is correct
2 Correct 39 ms 47340 KB Output is correct
3 Correct 34 ms 47340 KB Output is correct
4 Correct 33 ms 47340 KB Output is correct
5 Correct 38 ms 47340 KB Output is correct
6 Correct 33 ms 47340 KB Output is correct
7 Correct 39 ms 47340 KB Output is correct
8 Correct 33 ms 47340 KB Output is correct
9 Correct 36 ms 47340 KB Output is correct
10 Correct 34 ms 47400 KB Output is correct
11 Correct 36 ms 47340 KB Output is correct
12 Correct 36 ms 47340 KB Output is correct
13 Correct 36 ms 47340 KB Output is correct
14 Correct 41 ms 47340 KB Output is correct
15 Correct 38 ms 47468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 47340 KB Output is correct
2 Correct 39 ms 47340 KB Output is correct
3 Correct 34 ms 47340 KB Output is correct
4 Correct 33 ms 47340 KB Output is correct
5 Correct 38 ms 47340 KB Output is correct
6 Correct 33 ms 47340 KB Output is correct
7 Correct 39 ms 47340 KB Output is correct
8 Correct 33 ms 47340 KB Output is correct
9 Correct 36 ms 47340 KB Output is correct
10 Correct 34 ms 47400 KB Output is correct
11 Correct 36 ms 47340 KB Output is correct
12 Correct 36 ms 47340 KB Output is correct
13 Correct 36 ms 47340 KB Output is correct
14 Correct 41 ms 47340 KB Output is correct
15 Correct 38 ms 47468 KB Output is correct
16 Correct 36 ms 47340 KB Output is correct
17 Correct 36 ms 47396 KB Output is correct
18 Correct 37 ms 47468 KB Output is correct
19 Correct 37 ms 47340 KB Output is correct
20 Correct 36 ms 47340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 47340 KB Output is correct
2 Correct 39 ms 47340 KB Output is correct
3 Correct 34 ms 47340 KB Output is correct
4 Correct 33 ms 47340 KB Output is correct
5 Correct 38 ms 47340 KB Output is correct
6 Correct 33 ms 47340 KB Output is correct
7 Correct 39 ms 47340 KB Output is correct
8 Correct 33 ms 47340 KB Output is correct
9 Correct 36 ms 47340 KB Output is correct
10 Correct 34 ms 47400 KB Output is correct
11 Correct 36 ms 47340 KB Output is correct
12 Correct 36 ms 47340 KB Output is correct
13 Correct 36 ms 47340 KB Output is correct
14 Correct 41 ms 47340 KB Output is correct
15 Correct 38 ms 47468 KB Output is correct
16 Correct 36 ms 47340 KB Output is correct
17 Correct 36 ms 47396 KB Output is correct
18 Correct 37 ms 47468 KB Output is correct
19 Correct 37 ms 47340 KB Output is correct
20 Correct 36 ms 47340 KB Output is correct
21 Correct 37 ms 47468 KB Output is correct
22 Correct 37 ms 47468 KB Output is correct
23 Correct 44 ms 47468 KB Output is correct
24 Correct 36 ms 47468 KB Output is correct
25 Correct 38 ms 47468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 52456 KB Output is correct
2 Correct 84 ms 53488 KB Output is correct
3 Correct 65 ms 52208 KB Output is correct
4 Correct 78 ms 53096 KB Output is correct
5 Correct 68 ms 52588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 58092 KB Output is correct
2 Correct 110 ms 58348 KB Output is correct
3 Correct 108 ms 58220 KB Output is correct
4 Correct 108 ms 58476 KB Output is correct
5 Correct 106 ms 58092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 58476 KB Output is correct
2 Correct 116 ms 58520 KB Output is correct
3 Correct 120 ms 58476 KB Output is correct
4 Correct 113 ms 58732 KB Output is correct
5 Correct 122 ms 58860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 47340 KB Output is correct
2 Correct 39 ms 47340 KB Output is correct
3 Correct 34 ms 47340 KB Output is correct
4 Correct 33 ms 47340 KB Output is correct
5 Correct 38 ms 47340 KB Output is correct
6 Correct 33 ms 47340 KB Output is correct
7 Correct 39 ms 47340 KB Output is correct
8 Correct 33 ms 47340 KB Output is correct
9 Correct 36 ms 47340 KB Output is correct
10 Correct 34 ms 47400 KB Output is correct
11 Correct 69 ms 52456 KB Output is correct
12 Correct 84 ms 53488 KB Output is correct
13 Correct 65 ms 52208 KB Output is correct
14 Correct 78 ms 53096 KB Output is correct
15 Correct 68 ms 52588 KB Output is correct
16 Correct 61 ms 51948 KB Output is correct
17 Correct 76 ms 53228 KB Output is correct
18 Correct 74 ms 52972 KB Output is correct
19 Correct 58 ms 51564 KB Output is correct
20 Correct 76 ms 53228 KB Output is correct
21 Correct 60 ms 52072 KB Output is correct
22 Correct 74 ms 52972 KB Output is correct
23 Correct 62 ms 52076 KB Output is correct
24 Correct 72 ms 52716 KB Output is correct
25 Correct 64 ms 52076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 47340 KB Output is correct
2 Correct 39 ms 47340 KB Output is correct
3 Correct 34 ms 47340 KB Output is correct
4 Correct 33 ms 47340 KB Output is correct
5 Correct 38 ms 47340 KB Output is correct
6 Correct 33 ms 47340 KB Output is correct
7 Correct 39 ms 47340 KB Output is correct
8 Correct 33 ms 47340 KB Output is correct
9 Correct 36 ms 47340 KB Output is correct
10 Correct 34 ms 47400 KB Output is correct
11 Correct 36 ms 47340 KB Output is correct
12 Correct 36 ms 47340 KB Output is correct
13 Correct 36 ms 47340 KB Output is correct
14 Correct 41 ms 47340 KB Output is correct
15 Correct 38 ms 47468 KB Output is correct
16 Correct 36 ms 47340 KB Output is correct
17 Correct 36 ms 47396 KB Output is correct
18 Correct 37 ms 47468 KB Output is correct
19 Correct 37 ms 47340 KB Output is correct
20 Correct 36 ms 47340 KB Output is correct
21 Correct 37 ms 47468 KB Output is correct
22 Correct 37 ms 47468 KB Output is correct
23 Correct 44 ms 47468 KB Output is correct
24 Correct 36 ms 47468 KB Output is correct
25 Correct 38 ms 47468 KB Output is correct
26 Correct 69 ms 52456 KB Output is correct
27 Correct 84 ms 53488 KB Output is correct
28 Correct 65 ms 52208 KB Output is correct
29 Correct 78 ms 53096 KB Output is correct
30 Correct 68 ms 52588 KB Output is correct
31 Correct 107 ms 58092 KB Output is correct
32 Correct 110 ms 58348 KB Output is correct
33 Correct 108 ms 58220 KB Output is correct
34 Correct 108 ms 58476 KB Output is correct
35 Correct 106 ms 58092 KB Output is correct
36 Correct 123 ms 58476 KB Output is correct
37 Correct 116 ms 58520 KB Output is correct
38 Correct 120 ms 58476 KB Output is correct
39 Correct 113 ms 58732 KB Output is correct
40 Correct 122 ms 58860 KB Output is correct
41 Correct 61 ms 51948 KB Output is correct
42 Correct 76 ms 53228 KB Output is correct
43 Correct 74 ms 52972 KB Output is correct
44 Correct 58 ms 51564 KB Output is correct
45 Correct 76 ms 53228 KB Output is correct
46 Correct 60 ms 52072 KB Output is correct
47 Correct 74 ms 52972 KB Output is correct
48 Correct 62 ms 52076 KB Output is correct
49 Correct 72 ms 52716 KB Output is correct
50 Correct 64 ms 52076 KB Output is correct
51 Correct 142 ms 56812 KB Output is correct
52 Correct 135 ms 57856 KB Output is correct
53 Correct 126 ms 56812 KB Output is correct
54 Correct 131 ms 57708 KB Output is correct
55 Correct 114 ms 56684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 47340 KB Output is correct
2 Correct 39 ms 47340 KB Output is correct
3 Correct 34 ms 47340 KB Output is correct
4 Correct 33 ms 47340 KB Output is correct
5 Correct 38 ms 47340 KB Output is correct
6 Correct 33 ms 47340 KB Output is correct
7 Correct 39 ms 47340 KB Output is correct
8 Correct 33 ms 47340 KB Output is correct
9 Correct 36 ms 47340 KB Output is correct
10 Correct 34 ms 47400 KB Output is correct
11 Correct 36 ms 47340 KB Output is correct
12 Correct 36 ms 47340 KB Output is correct
13 Correct 36 ms 47340 KB Output is correct
14 Correct 41 ms 47340 KB Output is correct
15 Correct 38 ms 47468 KB Output is correct
16 Correct 36 ms 47340 KB Output is correct
17 Correct 36 ms 47396 KB Output is correct
18 Correct 37 ms 47468 KB Output is correct
19 Correct 37 ms 47340 KB Output is correct
20 Correct 36 ms 47340 KB Output is correct
21 Correct 37 ms 47468 KB Output is correct
22 Correct 37 ms 47468 KB Output is correct
23 Correct 44 ms 47468 KB Output is correct
24 Correct 36 ms 47468 KB Output is correct
25 Correct 38 ms 47468 KB Output is correct
26 Correct 69 ms 52456 KB Output is correct
27 Correct 84 ms 53488 KB Output is correct
28 Correct 65 ms 52208 KB Output is correct
29 Correct 78 ms 53096 KB Output is correct
30 Correct 68 ms 52588 KB Output is correct
31 Correct 107 ms 58092 KB Output is correct
32 Correct 110 ms 58348 KB Output is correct
33 Correct 108 ms 58220 KB Output is correct
34 Correct 108 ms 58476 KB Output is correct
35 Correct 106 ms 58092 KB Output is correct
36 Correct 123 ms 58476 KB Output is correct
37 Correct 116 ms 58520 KB Output is correct
38 Correct 120 ms 58476 KB Output is correct
39 Correct 113 ms 58732 KB Output is correct
40 Correct 122 ms 58860 KB Output is correct
41 Correct 61 ms 51948 KB Output is correct
42 Correct 76 ms 53228 KB Output is correct
43 Correct 74 ms 52972 KB Output is correct
44 Correct 58 ms 51564 KB Output is correct
45 Correct 76 ms 53228 KB Output is correct
46 Correct 60 ms 52072 KB Output is correct
47 Correct 74 ms 52972 KB Output is correct
48 Correct 62 ms 52076 KB Output is correct
49 Correct 72 ms 52716 KB Output is correct
50 Correct 64 ms 52076 KB Output is correct
51 Correct 142 ms 56812 KB Output is correct
52 Correct 135 ms 57856 KB Output is correct
53 Correct 126 ms 56812 KB Output is correct
54 Correct 131 ms 57708 KB Output is correct
55 Correct 114 ms 56684 KB Output is correct
56 Execution timed out 1090 ms 135592 KB Time limit exceeded
57 Halted 0 ms 0 KB -