Submission #689785

# Submission time Handle Problem Language Result Execution time Memory
689785 2023-01-29T11:28:11 Z zeroesandones Pilot (NOI19_pilot) C++17
100 / 100
368 ms 52204 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "

#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb emplace_back

ll c2(ll x) {
    return (x * (x - 1)) / 2;
}

void solve()
{
    ll n, q;
    cin >> n >> q;

    ll a[n + 2] = {};
    FOR(i, 1, n + 1) {
        cin >> a[i];
    }

    stack<ll> st;
    st.push(0);
    a[0] = 1e15;

    ll l[n + 1], r[n + 1];
    FOR(i, 1, n + 1) {
        while(a[st.top()] < a[i])
            st.pop();
        l[i] = st.top();
        st.push(i);
    }

    while(!st.empty()) st.pop();
    st.push(n + 1);
    a[n + 1] = 1e15;
    FORD(i, n, 1) {
        while(a[st.top()] <= a[i])
            st.pop();
        r[i] = st.top();
        st.push(i);
    }

    ll total[(ll) 1e6 + 6] = {};
    FOR(i, 1, n + 1) {
        total[a[i]] += (i - l[i]) * (r[i] - i);
    }
    FOR(i, 1, ((ll) 1e6 + 6)) {
        total[i] += total[i - 1];
    }

    while(q--) {
        ll x;
        cin >> x;
        cout << total[x] << nl;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8020 KB Output is correct
2 Correct 6 ms 8020 KB Output is correct
3 Correct 7 ms 8144 KB Output is correct
4 Correct 6 ms 8020 KB Output is correct
5 Correct 6 ms 8020 KB Output is correct
6 Correct 7 ms 8068 KB Output is correct
7 Correct 7 ms 8020 KB Output is correct
8 Correct 6 ms 8020 KB Output is correct
9 Correct 7 ms 8020 KB Output is correct
10 Correct 7 ms 8136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8020 KB Output is correct
2 Correct 6 ms 8020 KB Output is correct
3 Correct 7 ms 8144 KB Output is correct
4 Correct 6 ms 8020 KB Output is correct
5 Correct 6 ms 8020 KB Output is correct
6 Correct 7 ms 8068 KB Output is correct
7 Correct 7 ms 8020 KB Output is correct
8 Correct 6 ms 8020 KB Output is correct
9 Correct 7 ms 8020 KB Output is correct
10 Correct 7 ms 8136 KB Output is correct
11 Correct 7 ms 8020 KB Output is correct
12 Correct 7 ms 8020 KB Output is correct
13 Correct 6 ms 8020 KB Output is correct
14 Correct 7 ms 8020 KB Output is correct
15 Correct 7 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8020 KB Output is correct
2 Correct 6 ms 8020 KB Output is correct
3 Correct 7 ms 8144 KB Output is correct
4 Correct 6 ms 8020 KB Output is correct
5 Correct 6 ms 8020 KB Output is correct
6 Correct 7 ms 8068 KB Output is correct
7 Correct 7 ms 8020 KB Output is correct
8 Correct 6 ms 8020 KB Output is correct
9 Correct 7 ms 8020 KB Output is correct
10 Correct 7 ms 8136 KB Output is correct
11 Correct 7 ms 8020 KB Output is correct
12 Correct 7 ms 8020 KB Output is correct
13 Correct 6 ms 8020 KB Output is correct
14 Correct 7 ms 8020 KB Output is correct
15 Correct 7 ms 8140 KB Output is correct
16 Correct 6 ms 8020 KB Output is correct
17 Correct 7 ms 8048 KB Output is correct
18 Correct 7 ms 8148 KB Output is correct
19 Correct 7 ms 8148 KB Output is correct
20 Correct 6 ms 8020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8020 KB Output is correct
2 Correct 6 ms 8020 KB Output is correct
3 Correct 7 ms 8144 KB Output is correct
4 Correct 6 ms 8020 KB Output is correct
5 Correct 6 ms 8020 KB Output is correct
6 Correct 7 ms 8068 KB Output is correct
7 Correct 7 ms 8020 KB Output is correct
8 Correct 6 ms 8020 KB Output is correct
9 Correct 7 ms 8020 KB Output is correct
10 Correct 7 ms 8136 KB Output is correct
11 Correct 7 ms 8020 KB Output is correct
12 Correct 7 ms 8020 KB Output is correct
13 Correct 6 ms 8020 KB Output is correct
14 Correct 7 ms 8020 KB Output is correct
15 Correct 7 ms 8140 KB Output is correct
16 Correct 6 ms 8020 KB Output is correct
17 Correct 7 ms 8048 KB Output is correct
18 Correct 7 ms 8148 KB Output is correct
19 Correct 7 ms 8148 KB Output is correct
20 Correct 6 ms 8020 KB Output is correct
21 Correct 6 ms 8148 KB Output is correct
22 Correct 7 ms 8148 KB Output is correct
23 Correct 7 ms 8148 KB Output is correct
24 Correct 7 ms 8096 KB Output is correct
25 Correct 7 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 10308 KB Output is correct
2 Correct 19 ms 10452 KB Output is correct
3 Correct 16 ms 10324 KB Output is correct
4 Correct 17 ms 10256 KB Output is correct
5 Correct 19 ms 10316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 12060 KB Output is correct
2 Correct 34 ms 12128 KB Output is correct
3 Correct 33 ms 11920 KB Output is correct
4 Correct 32 ms 12116 KB Output is correct
5 Correct 34 ms 12000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 12048 KB Output is correct
2 Correct 34 ms 11956 KB Output is correct
3 Correct 40 ms 11988 KB Output is correct
4 Correct 35 ms 12176 KB Output is correct
5 Correct 38 ms 12012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8020 KB Output is correct
2 Correct 6 ms 8020 KB Output is correct
3 Correct 7 ms 8144 KB Output is correct
4 Correct 6 ms 8020 KB Output is correct
5 Correct 6 ms 8020 KB Output is correct
6 Correct 7 ms 8068 KB Output is correct
7 Correct 7 ms 8020 KB Output is correct
8 Correct 6 ms 8020 KB Output is correct
9 Correct 7 ms 8020 KB Output is correct
10 Correct 7 ms 8136 KB Output is correct
11 Correct 17 ms 10308 KB Output is correct
12 Correct 19 ms 10452 KB Output is correct
13 Correct 16 ms 10324 KB Output is correct
14 Correct 17 ms 10256 KB Output is correct
15 Correct 19 ms 10316 KB Output is correct
16 Correct 16 ms 10276 KB Output is correct
17 Correct 21 ms 10320 KB Output is correct
18 Correct 22 ms 10452 KB Output is correct
19 Correct 16 ms 10264 KB Output is correct
20 Correct 17 ms 10324 KB Output is correct
21 Correct 16 ms 10284 KB Output is correct
22 Correct 17 ms 10320 KB Output is correct
23 Correct 17 ms 10452 KB Output is correct
24 Correct 18 ms 10168 KB Output is correct
25 Correct 16 ms 10324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8020 KB Output is correct
2 Correct 6 ms 8020 KB Output is correct
3 Correct 7 ms 8144 KB Output is correct
4 Correct 6 ms 8020 KB Output is correct
5 Correct 6 ms 8020 KB Output is correct
6 Correct 7 ms 8068 KB Output is correct
7 Correct 7 ms 8020 KB Output is correct
8 Correct 6 ms 8020 KB Output is correct
9 Correct 7 ms 8020 KB Output is correct
10 Correct 7 ms 8136 KB Output is correct
11 Correct 7 ms 8020 KB Output is correct
12 Correct 7 ms 8020 KB Output is correct
13 Correct 6 ms 8020 KB Output is correct
14 Correct 7 ms 8020 KB Output is correct
15 Correct 7 ms 8140 KB Output is correct
16 Correct 6 ms 8020 KB Output is correct
17 Correct 7 ms 8048 KB Output is correct
18 Correct 7 ms 8148 KB Output is correct
19 Correct 7 ms 8148 KB Output is correct
20 Correct 6 ms 8020 KB Output is correct
21 Correct 6 ms 8148 KB Output is correct
22 Correct 7 ms 8148 KB Output is correct
23 Correct 7 ms 8148 KB Output is correct
24 Correct 7 ms 8096 KB Output is correct
25 Correct 7 ms 8148 KB Output is correct
26 Correct 17 ms 10308 KB Output is correct
27 Correct 19 ms 10452 KB Output is correct
28 Correct 16 ms 10324 KB Output is correct
29 Correct 17 ms 10256 KB Output is correct
30 Correct 19 ms 10316 KB Output is correct
31 Correct 35 ms 12060 KB Output is correct
32 Correct 34 ms 12128 KB Output is correct
33 Correct 33 ms 11920 KB Output is correct
34 Correct 32 ms 12116 KB Output is correct
35 Correct 34 ms 12000 KB Output is correct
36 Correct 39 ms 12048 KB Output is correct
37 Correct 34 ms 11956 KB Output is correct
38 Correct 40 ms 11988 KB Output is correct
39 Correct 35 ms 12176 KB Output is correct
40 Correct 38 ms 12012 KB Output is correct
41 Correct 16 ms 10276 KB Output is correct
42 Correct 21 ms 10320 KB Output is correct
43 Correct 22 ms 10452 KB Output is correct
44 Correct 16 ms 10264 KB Output is correct
45 Correct 17 ms 10324 KB Output is correct
46 Correct 16 ms 10284 KB Output is correct
47 Correct 17 ms 10320 KB Output is correct
48 Correct 17 ms 10452 KB Output is correct
49 Correct 18 ms 10168 KB Output is correct
50 Correct 16 ms 10324 KB Output is correct
51 Correct 39 ms 11172 KB Output is correct
52 Correct 39 ms 12232 KB Output is correct
53 Correct 37 ms 12340 KB Output is correct
54 Correct 43 ms 12184 KB Output is correct
55 Correct 40 ms 12348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8020 KB Output is correct
2 Correct 6 ms 8020 KB Output is correct
3 Correct 7 ms 8144 KB Output is correct
4 Correct 6 ms 8020 KB Output is correct
5 Correct 6 ms 8020 KB Output is correct
6 Correct 7 ms 8068 KB Output is correct
7 Correct 7 ms 8020 KB Output is correct
8 Correct 6 ms 8020 KB Output is correct
9 Correct 7 ms 8020 KB Output is correct
10 Correct 7 ms 8136 KB Output is correct
11 Correct 7 ms 8020 KB Output is correct
12 Correct 7 ms 8020 KB Output is correct
13 Correct 6 ms 8020 KB Output is correct
14 Correct 7 ms 8020 KB Output is correct
15 Correct 7 ms 8140 KB Output is correct
16 Correct 6 ms 8020 KB Output is correct
17 Correct 7 ms 8048 KB Output is correct
18 Correct 7 ms 8148 KB Output is correct
19 Correct 7 ms 8148 KB Output is correct
20 Correct 6 ms 8020 KB Output is correct
21 Correct 6 ms 8148 KB Output is correct
22 Correct 7 ms 8148 KB Output is correct
23 Correct 7 ms 8148 KB Output is correct
24 Correct 7 ms 8096 KB Output is correct
25 Correct 7 ms 8148 KB Output is correct
26 Correct 17 ms 10308 KB Output is correct
27 Correct 19 ms 10452 KB Output is correct
28 Correct 16 ms 10324 KB Output is correct
29 Correct 17 ms 10256 KB Output is correct
30 Correct 19 ms 10316 KB Output is correct
31 Correct 35 ms 12060 KB Output is correct
32 Correct 34 ms 12128 KB Output is correct
33 Correct 33 ms 11920 KB Output is correct
34 Correct 32 ms 12116 KB Output is correct
35 Correct 34 ms 12000 KB Output is correct
36 Correct 39 ms 12048 KB Output is correct
37 Correct 34 ms 11956 KB Output is correct
38 Correct 40 ms 11988 KB Output is correct
39 Correct 35 ms 12176 KB Output is correct
40 Correct 38 ms 12012 KB Output is correct
41 Correct 16 ms 10276 KB Output is correct
42 Correct 21 ms 10320 KB Output is correct
43 Correct 22 ms 10452 KB Output is correct
44 Correct 16 ms 10264 KB Output is correct
45 Correct 17 ms 10324 KB Output is correct
46 Correct 16 ms 10284 KB Output is correct
47 Correct 17 ms 10320 KB Output is correct
48 Correct 17 ms 10452 KB Output is correct
49 Correct 18 ms 10168 KB Output is correct
50 Correct 16 ms 10324 KB Output is correct
51 Correct 39 ms 11172 KB Output is correct
52 Correct 39 ms 12232 KB Output is correct
53 Correct 37 ms 12340 KB Output is correct
54 Correct 43 ms 12184 KB Output is correct
55 Correct 40 ms 12348 KB Output is correct
56 Correct 368 ms 50712 KB Output is correct
57 Correct 331 ms 51312 KB Output is correct
58 Correct 362 ms 48532 KB Output is correct
59 Correct 302 ms 49452 KB Output is correct
60 Correct 329 ms 52204 KB Output is correct