답안 #1014541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014541 2024-07-05T06:23:44 Z ttttttttttttth Pilot (NOI19_pilot) C++17
100 / 100
229 ms 52324 KB
// Author: Ivan Teo 
// Created: Fri Jul  5 12:08:34 2024

#define TASKNAME "636085S" 
#include <bits/stdc++.h>
using namespace std;

#define fore(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define int long long
using vi = vector<int>;
using ii = pair<int, int>;
#define pb emplace_back
#define fi first
#define se second
#define sz(v) ((int)v.size())
#define all(v) v.begin() + 1, v.end()
#define alll(v) v.begin(), v.end()
#define db(x) cerr << "[" << #x << " = " << x << "]"
#define el cerr << "\n=========================================\n"
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r)
{
    assert(l <= r);
    return uniform_int_distribution<int> (l, r)(rng);
}
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { template<typename... Args> Vec(int n = 0, Args... args) : vector < Vec < D - 1, T >> (n, Vec < D - 1, T > (args...)) {} };
template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, const T &val = T()) : vector<T>(n, val) {} };

void solve()
{
    int n, q;
    cin >> n >> q;
    vi a(n + 1);
    fore(i, 1, n) cin >> a[i];
    stack<int> st;
    vi l(n + 1), r(n + 1);
    fore(i, 1, n)
    {
        while (sz(st) && a[i] >= a[st.top()]) st.pop();
        l[i] = st.empty() ? 1 : (st.top() + 1);
        st.push(i);
    }
    st = stack<int>();
    for (int i = n; i >= 1; i--)
    {
        while (sz(st) && a[i] > a[st.top()]) st.pop();
        r[i] = st.empty() ? n : (st.top() - 1);
        st.push(i);
    }
    vi ans(1e6 + 1);
    fore(i, 1, n)
        ans[a[i]] += (i - l[i] + 1) * (r[i] - i + 1);
    fore(i, 1, 1e6) ans[i] += ans[i - 1];
    while (q--)
    {
        int x; cin >> x;
        cout << ans[x] << '\n';
    }
}

signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    if (fopen(TASKNAME ".inp", "r"))
    {
        freopen(TASKNAME ".inp", "r", stdin);
        freopen(TASKNAME ".out", "w", stdout);
    }
    int tc = 1;
    // cin >> tc;
    while (tc--) solve();
    el, cerr << "Execution Time: " << 1.0 * clock() / CLOCKS_PER_SEC << "s", el;
    return 0;
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen(TASKNAME ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen(TASKNAME ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 4 ms 8280 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8076 KB Output is correct
7 Correct 6 ms 8280 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 4 ms 8280 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8076 KB Output is correct
7 Correct 6 ms 8280 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 5 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 4 ms 8284 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 4 ms 8280 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8076 KB Output is correct
7 Correct 6 ms 8280 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 5 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 4 ms 8284 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 4 ms 8280 KB Output is correct
17 Correct 4 ms 8284 KB Output is correct
18 Correct 5 ms 8244 KB Output is correct
19 Correct 4 ms 8284 KB Output is correct
20 Correct 5 ms 8280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 4 ms 8280 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8076 KB Output is correct
7 Correct 6 ms 8280 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 5 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 4 ms 8284 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 4 ms 8280 KB Output is correct
17 Correct 4 ms 8284 KB Output is correct
18 Correct 5 ms 8244 KB Output is correct
19 Correct 4 ms 8284 KB Output is correct
20 Correct 5 ms 8280 KB Output is correct
21 Correct 5 ms 8284 KB Output is correct
22 Correct 4 ms 8344 KB Output is correct
23 Correct 4 ms 8340 KB Output is correct
24 Correct 4 ms 8280 KB Output is correct
25 Correct 4 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 11096 KB Output is correct
2 Correct 13 ms 11124 KB Output is correct
3 Correct 12 ms 11016 KB Output is correct
4 Correct 12 ms 10844 KB Output is correct
5 Correct 12 ms 10828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 13136 KB Output is correct
2 Correct 24 ms 13264 KB Output is correct
3 Correct 25 ms 13328 KB Output is correct
4 Correct 23 ms 13300 KB Output is correct
5 Correct 22 ms 13136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 13404 KB Output is correct
2 Correct 23 ms 13360 KB Output is correct
3 Correct 23 ms 13400 KB Output is correct
4 Correct 24 ms 13652 KB Output is correct
5 Correct 24 ms 13392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 4 ms 8280 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8076 KB Output is correct
7 Correct 6 ms 8280 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 13 ms 11096 KB Output is correct
12 Correct 13 ms 11124 KB Output is correct
13 Correct 12 ms 11016 KB Output is correct
14 Correct 12 ms 10844 KB Output is correct
15 Correct 12 ms 10828 KB Output is correct
16 Correct 16 ms 10844 KB Output is correct
17 Correct 13 ms 11096 KB Output is correct
18 Correct 13 ms 11156 KB Output is correct
19 Correct 12 ms 10844 KB Output is correct
20 Correct 13 ms 11096 KB Output is correct
21 Correct 13 ms 10844 KB Output is correct
22 Correct 15 ms 10856 KB Output is correct
23 Correct 13 ms 11100 KB Output is correct
24 Correct 13 ms 11020 KB Output is correct
25 Correct 12 ms 10972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 4 ms 8280 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8076 KB Output is correct
7 Correct 6 ms 8280 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 5 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 4 ms 8284 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 4 ms 8280 KB Output is correct
17 Correct 4 ms 8284 KB Output is correct
18 Correct 5 ms 8244 KB Output is correct
19 Correct 4 ms 8284 KB Output is correct
20 Correct 5 ms 8280 KB Output is correct
21 Correct 5 ms 8284 KB Output is correct
22 Correct 4 ms 8344 KB Output is correct
23 Correct 4 ms 8340 KB Output is correct
24 Correct 4 ms 8280 KB Output is correct
25 Correct 4 ms 8284 KB Output is correct
26 Correct 13 ms 11096 KB Output is correct
27 Correct 13 ms 11124 KB Output is correct
28 Correct 12 ms 11016 KB Output is correct
29 Correct 12 ms 10844 KB Output is correct
30 Correct 12 ms 10828 KB Output is correct
31 Correct 22 ms 13136 KB Output is correct
32 Correct 24 ms 13264 KB Output is correct
33 Correct 25 ms 13328 KB Output is correct
34 Correct 23 ms 13300 KB Output is correct
35 Correct 22 ms 13136 KB Output is correct
36 Correct 23 ms 13404 KB Output is correct
37 Correct 23 ms 13360 KB Output is correct
38 Correct 23 ms 13400 KB Output is correct
39 Correct 24 ms 13652 KB Output is correct
40 Correct 24 ms 13392 KB Output is correct
41 Correct 16 ms 10844 KB Output is correct
42 Correct 13 ms 11096 KB Output is correct
43 Correct 13 ms 11156 KB Output is correct
44 Correct 12 ms 10844 KB Output is correct
45 Correct 13 ms 11096 KB Output is correct
46 Correct 13 ms 10844 KB Output is correct
47 Correct 15 ms 10856 KB Output is correct
48 Correct 13 ms 11100 KB Output is correct
49 Correct 13 ms 11020 KB Output is correct
50 Correct 12 ms 10972 KB Output is correct
51 Correct 24 ms 12376 KB Output is correct
52 Correct 27 ms 12412 KB Output is correct
53 Correct 28 ms 12372 KB Output is correct
54 Correct 29 ms 12372 KB Output is correct
55 Correct 25 ms 12376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 4 ms 8280 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8076 KB Output is correct
7 Correct 6 ms 8280 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 5 ms 8284 KB Output is correct
12 Correct 4 ms 8284 KB Output is correct
13 Correct 4 ms 8284 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 4 ms 8280 KB Output is correct
17 Correct 4 ms 8284 KB Output is correct
18 Correct 5 ms 8244 KB Output is correct
19 Correct 4 ms 8284 KB Output is correct
20 Correct 5 ms 8280 KB Output is correct
21 Correct 5 ms 8284 KB Output is correct
22 Correct 4 ms 8344 KB Output is correct
23 Correct 4 ms 8340 KB Output is correct
24 Correct 4 ms 8280 KB Output is correct
25 Correct 4 ms 8284 KB Output is correct
26 Correct 13 ms 11096 KB Output is correct
27 Correct 13 ms 11124 KB Output is correct
28 Correct 12 ms 11016 KB Output is correct
29 Correct 12 ms 10844 KB Output is correct
30 Correct 12 ms 10828 KB Output is correct
31 Correct 22 ms 13136 KB Output is correct
32 Correct 24 ms 13264 KB Output is correct
33 Correct 25 ms 13328 KB Output is correct
34 Correct 23 ms 13300 KB Output is correct
35 Correct 22 ms 13136 KB Output is correct
36 Correct 23 ms 13404 KB Output is correct
37 Correct 23 ms 13360 KB Output is correct
38 Correct 23 ms 13400 KB Output is correct
39 Correct 24 ms 13652 KB Output is correct
40 Correct 24 ms 13392 KB Output is correct
41 Correct 16 ms 10844 KB Output is correct
42 Correct 13 ms 11096 KB Output is correct
43 Correct 13 ms 11156 KB Output is correct
44 Correct 12 ms 10844 KB Output is correct
45 Correct 13 ms 11096 KB Output is correct
46 Correct 13 ms 10844 KB Output is correct
47 Correct 15 ms 10856 KB Output is correct
48 Correct 13 ms 11100 KB Output is correct
49 Correct 13 ms 11020 KB Output is correct
50 Correct 12 ms 10972 KB Output is correct
51 Correct 24 ms 12376 KB Output is correct
52 Correct 27 ms 12412 KB Output is correct
53 Correct 28 ms 12372 KB Output is correct
54 Correct 29 ms 12372 KB Output is correct
55 Correct 25 ms 12376 KB Output is correct
56 Correct 229 ms 50768 KB Output is correct
57 Correct 215 ms 51304 KB Output is correct
58 Correct 196 ms 48720 KB Output is correct
59 Correct 213 ms 49468 KB Output is correct
60 Correct 215 ms 52324 KB Output is correct