답안 #329319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
329319 2020-11-20T14:45:00 Z BeanZ Pilot (NOI19_pilot) C++14
100 / 100
464 ms 52332 KB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
const int lg = 60;
const int mod = 998244353;
const long long oo = 1e18;
const int lim = 1e6;
ll cnt[N], h[N], r[N], l[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("A.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> h[i];
    vector<ll> st;
    for (int i = 1; i <= n; i++){
        while (st.size()){
            if (h[st.back()] <= h[i]){
                st.pop_back();
            } else break;
        }
        if (st.size()) l[i] = st.back() + 1;
        else l[i] = 1;
        st.push_back(i);
    }
    st.clear();
    for (int i = n; i >= 1; i--){
        while (st.size()){
            if (h[st.back()] < h[i]){
                st.pop_back();
            } else break;
        }
        if (st.size()) r[i] = st.back() - 1;
        else r[i] = n;
        st.push_back(i);
    }
    for (int i = 1; i <= n; i++){
        cnt[h[i]] += (i - l[i] + 1) * (r[i] - i + 1);
    }
    for (int i = 2; i <= lim; i++) cnt[i] += cnt[i - 1];
    while (q--){
        ll x;
        cin >> x;
        cout << cnt[x] << endl;
    }
}
/*
*/

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   17 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8192 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8192 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 9 ms 8172 KB Output is correct
7 Correct 7 ms 8312 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 6 ms 8172 KB Output is correct
10 Correct 7 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8192 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8192 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 9 ms 8172 KB Output is correct
7 Correct 7 ms 8312 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 6 ms 8172 KB Output is correct
10 Correct 7 ms 8172 KB Output is correct
11 Correct 6 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 6 ms 8172 KB Output is correct
14 Correct 7 ms 8172 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8192 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8192 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 9 ms 8172 KB Output is correct
7 Correct 7 ms 8312 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 6 ms 8172 KB Output is correct
10 Correct 7 ms 8172 KB Output is correct
11 Correct 6 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 6 ms 8172 KB Output is correct
14 Correct 7 ms 8172 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8192 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8192 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 9 ms 8172 KB Output is correct
7 Correct 7 ms 8312 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 6 ms 8172 KB Output is correct
10 Correct 7 ms 8172 KB Output is correct
11 Correct 6 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 6 ms 8172 KB Output is correct
14 Correct 7 ms 8172 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
21 Correct 7 ms 8172 KB Output is correct
22 Correct 7 ms 8300 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 8 ms 8300 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 10988 KB Output is correct
2 Correct 21 ms 11116 KB Output is correct
3 Correct 20 ms 10988 KB Output is correct
4 Correct 21 ms 10860 KB Output is correct
5 Correct 19 ms 10860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 13416 KB Output is correct
2 Correct 47 ms 13416 KB Output is correct
3 Correct 45 ms 13288 KB Output is correct
4 Correct 45 ms 13544 KB Output is correct
5 Correct 45 ms 13288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 13500 KB Output is correct
2 Correct 47 ms 13416 KB Output is correct
3 Correct 48 ms 13416 KB Output is correct
4 Correct 47 ms 13672 KB Output is correct
5 Correct 49 ms 13672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8192 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8192 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 9 ms 8172 KB Output is correct
7 Correct 7 ms 8312 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 6 ms 8172 KB Output is correct
10 Correct 7 ms 8172 KB Output is correct
11 Correct 19 ms 10988 KB Output is correct
12 Correct 21 ms 11116 KB Output is correct
13 Correct 20 ms 10988 KB Output is correct
14 Correct 21 ms 10860 KB Output is correct
15 Correct 19 ms 10860 KB Output is correct
16 Correct 19 ms 10860 KB Output is correct
17 Correct 22 ms 11116 KB Output is correct
18 Correct 23 ms 11244 KB Output is correct
19 Correct 19 ms 10860 KB Output is correct
20 Correct 22 ms 11116 KB Output is correct
21 Correct 19 ms 10860 KB Output is correct
22 Correct 21 ms 10988 KB Output is correct
23 Correct 22 ms 11116 KB Output is correct
24 Correct 21 ms 10988 KB Output is correct
25 Correct 20 ms 11116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8192 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8192 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 9 ms 8172 KB Output is correct
7 Correct 7 ms 8312 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 6 ms 8172 KB Output is correct
10 Correct 7 ms 8172 KB Output is correct
11 Correct 6 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 6 ms 8172 KB Output is correct
14 Correct 7 ms 8172 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
21 Correct 7 ms 8172 KB Output is correct
22 Correct 7 ms 8300 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 8 ms 8300 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
26 Correct 19 ms 10988 KB Output is correct
27 Correct 21 ms 11116 KB Output is correct
28 Correct 20 ms 10988 KB Output is correct
29 Correct 21 ms 10860 KB Output is correct
30 Correct 19 ms 10860 KB Output is correct
31 Correct 46 ms 13416 KB Output is correct
32 Correct 47 ms 13416 KB Output is correct
33 Correct 45 ms 13288 KB Output is correct
34 Correct 45 ms 13544 KB Output is correct
35 Correct 45 ms 13288 KB Output is correct
36 Correct 47 ms 13500 KB Output is correct
37 Correct 47 ms 13416 KB Output is correct
38 Correct 48 ms 13416 KB Output is correct
39 Correct 47 ms 13672 KB Output is correct
40 Correct 49 ms 13672 KB Output is correct
41 Correct 19 ms 10860 KB Output is correct
42 Correct 22 ms 11116 KB Output is correct
43 Correct 23 ms 11244 KB Output is correct
44 Correct 19 ms 10860 KB Output is correct
45 Correct 22 ms 11116 KB Output is correct
46 Correct 19 ms 10860 KB Output is correct
47 Correct 21 ms 10988 KB Output is correct
48 Correct 22 ms 11116 KB Output is correct
49 Correct 21 ms 10988 KB Output is correct
50 Correct 20 ms 11116 KB Output is correct
51 Correct 47 ms 12524 KB Output is correct
52 Correct 50 ms 12396 KB Output is correct
53 Correct 46 ms 12524 KB Output is correct
54 Correct 50 ms 12268 KB Output is correct
55 Correct 48 ms 12524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 7 ms 8192 KB Output is correct
3 Correct 7 ms 8172 KB Output is correct
4 Correct 7 ms 8192 KB Output is correct
5 Correct 7 ms 8172 KB Output is correct
6 Correct 9 ms 8172 KB Output is correct
7 Correct 7 ms 8312 KB Output is correct
8 Correct 7 ms 8172 KB Output is correct
9 Correct 6 ms 8172 KB Output is correct
10 Correct 7 ms 8172 KB Output is correct
11 Correct 6 ms 8172 KB Output is correct
12 Correct 7 ms 8172 KB Output is correct
13 Correct 6 ms 8172 KB Output is correct
14 Correct 7 ms 8172 KB Output is correct
15 Correct 7 ms 8172 KB Output is correct
16 Correct 7 ms 8172 KB Output is correct
17 Correct 7 ms 8172 KB Output is correct
18 Correct 7 ms 8172 KB Output is correct
19 Correct 7 ms 8172 KB Output is correct
20 Correct 8 ms 8172 KB Output is correct
21 Correct 7 ms 8172 KB Output is correct
22 Correct 7 ms 8300 KB Output is correct
23 Correct 8 ms 8172 KB Output is correct
24 Correct 8 ms 8300 KB Output is correct
25 Correct 7 ms 8172 KB Output is correct
26 Correct 19 ms 10988 KB Output is correct
27 Correct 21 ms 11116 KB Output is correct
28 Correct 20 ms 10988 KB Output is correct
29 Correct 21 ms 10860 KB Output is correct
30 Correct 19 ms 10860 KB Output is correct
31 Correct 46 ms 13416 KB Output is correct
32 Correct 47 ms 13416 KB Output is correct
33 Correct 45 ms 13288 KB Output is correct
34 Correct 45 ms 13544 KB Output is correct
35 Correct 45 ms 13288 KB Output is correct
36 Correct 47 ms 13500 KB Output is correct
37 Correct 47 ms 13416 KB Output is correct
38 Correct 48 ms 13416 KB Output is correct
39 Correct 47 ms 13672 KB Output is correct
40 Correct 49 ms 13672 KB Output is correct
41 Correct 19 ms 10860 KB Output is correct
42 Correct 22 ms 11116 KB Output is correct
43 Correct 23 ms 11244 KB Output is correct
44 Correct 19 ms 10860 KB Output is correct
45 Correct 22 ms 11116 KB Output is correct
46 Correct 19 ms 10860 KB Output is correct
47 Correct 21 ms 10988 KB Output is correct
48 Correct 22 ms 11116 KB Output is correct
49 Correct 21 ms 10988 KB Output is correct
50 Correct 20 ms 11116 KB Output is correct
51 Correct 47 ms 12524 KB Output is correct
52 Correct 50 ms 12396 KB Output is correct
53 Correct 46 ms 12524 KB Output is correct
54 Correct 50 ms 12268 KB Output is correct
55 Correct 48 ms 12524 KB Output is correct
56 Correct 451 ms 50796 KB Output is correct
57 Correct 438 ms 51308 KB Output is correct
58 Correct 417 ms 48748 KB Output is correct
59 Correct 426 ms 49496 KB Output is correct
60 Correct 464 ms 52332 KB Output is correct