답안 #224230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
224230 2020-04-17T14:34:49 Z bortoz Pilot (NOI19_pilot) C++17
100 / 100
441 ms 27512 KB
#pragma GCC optimize("O3")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define fi first
#define se second

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N, Q;
  cin >> N >> Q;

  vector<int> H(N);
  for (int& i : H) {
    cin >> i;
  }

  vector<int> lx(N, -1), rx(N, N);
  vector<int> stk;
  for (int i = 0; i < N; i++) {
    while (!stk.empty() && H[i] > H[stk.back()]) {
      stk.pop_back();
    }
    if (!stk.empty()) lx[i] = stk.back();
    stk.push_back(i);
  }
  stk.clear();
  for (int i = N - 1; i >= 0; i--) {
    while (!stk.empty() && H[i] >= H[stk.back()]) {
      stk.pop_back();
    }
    if (!stk.empty()) rx[i] = stk.back();
    stk.push_back(i);
  }

  vector<ll> res(1e6 + 1);
  for (int i = 0; i < N; i++) {
    res[H[i]] += 1ll * (i - lx[i]) * (rx[i] - i);
  }
  for (int i = 1; i <= 1e6; i++) {
    res[i] += res[i - 1];
  }

  for (int i = 0; i < Q; i++) {
    int Y;
    cin >> Y;
    cout << res[Y] << '\n';
  }

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8192 KB Output is correct
2 Correct 10 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 10 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8320 KB Output is correct
7 Correct 12 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 9 ms 8192 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8192 KB Output is correct
2 Correct 10 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 10 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8320 KB Output is correct
7 Correct 12 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 9 ms 8192 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
11 Correct 9 ms 8192 KB Output is correct
12 Correct 9 ms 8192 KB Output is correct
13 Correct 10 ms 8192 KB Output is correct
14 Correct 10 ms 8192 KB Output is correct
15 Correct 10 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8192 KB Output is correct
2 Correct 10 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 10 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8320 KB Output is correct
7 Correct 12 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 9 ms 8192 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
11 Correct 9 ms 8192 KB Output is correct
12 Correct 9 ms 8192 KB Output is correct
13 Correct 10 ms 8192 KB Output is correct
14 Correct 10 ms 8192 KB Output is correct
15 Correct 10 ms 8192 KB Output is correct
16 Correct 10 ms 8192 KB Output is correct
17 Correct 10 ms 8192 KB Output is correct
18 Correct 10 ms 8192 KB Output is correct
19 Correct 10 ms 8192 KB Output is correct
20 Correct 10 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8192 KB Output is correct
2 Correct 10 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 10 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8320 KB Output is correct
7 Correct 12 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 9 ms 8192 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
11 Correct 9 ms 8192 KB Output is correct
12 Correct 9 ms 8192 KB Output is correct
13 Correct 10 ms 8192 KB Output is correct
14 Correct 10 ms 8192 KB Output is correct
15 Correct 10 ms 8192 KB Output is correct
16 Correct 10 ms 8192 KB Output is correct
17 Correct 10 ms 8192 KB Output is correct
18 Correct 10 ms 8192 KB Output is correct
19 Correct 10 ms 8192 KB Output is correct
20 Correct 10 ms 8192 KB Output is correct
21 Correct 10 ms 8320 KB Output is correct
22 Correct 10 ms 8192 KB Output is correct
23 Correct 10 ms 8192 KB Output is correct
24 Correct 10 ms 8192 KB Output is correct
25 Correct 10 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 9696 KB Output is correct
2 Correct 25 ms 9600 KB Output is correct
3 Correct 24 ms 9600 KB Output is correct
4 Correct 24 ms 9600 KB Output is correct
5 Correct 23 ms 9600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 11124 KB Output is correct
2 Correct 46 ms 11124 KB Output is correct
3 Correct 49 ms 11124 KB Output is correct
4 Correct 45 ms 11128 KB Output is correct
5 Correct 52 ms 11124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 11128 KB Output is correct
2 Correct 50 ms 11128 KB Output is correct
3 Correct 51 ms 11124 KB Output is correct
4 Correct 52 ms 11124 KB Output is correct
5 Correct 52 ms 11124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8192 KB Output is correct
2 Correct 10 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 10 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8320 KB Output is correct
7 Correct 12 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 9 ms 8192 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
11 Correct 24 ms 9696 KB Output is correct
12 Correct 25 ms 9600 KB Output is correct
13 Correct 24 ms 9600 KB Output is correct
14 Correct 24 ms 9600 KB Output is correct
15 Correct 23 ms 9600 KB Output is correct
16 Correct 23 ms 9600 KB Output is correct
17 Correct 24 ms 9600 KB Output is correct
18 Correct 26 ms 9720 KB Output is correct
19 Correct 23 ms 9600 KB Output is correct
20 Correct 25 ms 9600 KB Output is correct
21 Correct 23 ms 9600 KB Output is correct
22 Correct 24 ms 9600 KB Output is correct
23 Correct 25 ms 9728 KB Output is correct
24 Correct 25 ms 9592 KB Output is correct
25 Correct 24 ms 9600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8192 KB Output is correct
2 Correct 10 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 10 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8320 KB Output is correct
7 Correct 12 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 9 ms 8192 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
11 Correct 9 ms 8192 KB Output is correct
12 Correct 9 ms 8192 KB Output is correct
13 Correct 10 ms 8192 KB Output is correct
14 Correct 10 ms 8192 KB Output is correct
15 Correct 10 ms 8192 KB Output is correct
16 Correct 10 ms 8192 KB Output is correct
17 Correct 10 ms 8192 KB Output is correct
18 Correct 10 ms 8192 KB Output is correct
19 Correct 10 ms 8192 KB Output is correct
20 Correct 10 ms 8192 KB Output is correct
21 Correct 10 ms 8320 KB Output is correct
22 Correct 10 ms 8192 KB Output is correct
23 Correct 10 ms 8192 KB Output is correct
24 Correct 10 ms 8192 KB Output is correct
25 Correct 10 ms 8192 KB Output is correct
26 Correct 24 ms 9696 KB Output is correct
27 Correct 25 ms 9600 KB Output is correct
28 Correct 24 ms 9600 KB Output is correct
29 Correct 24 ms 9600 KB Output is correct
30 Correct 23 ms 9600 KB Output is correct
31 Correct 45 ms 11124 KB Output is correct
32 Correct 46 ms 11124 KB Output is correct
33 Correct 49 ms 11124 KB Output is correct
34 Correct 45 ms 11128 KB Output is correct
35 Correct 52 ms 11124 KB Output is correct
36 Correct 49 ms 11128 KB Output is correct
37 Correct 50 ms 11128 KB Output is correct
38 Correct 51 ms 11124 KB Output is correct
39 Correct 52 ms 11124 KB Output is correct
40 Correct 52 ms 11124 KB Output is correct
41 Correct 23 ms 9600 KB Output is correct
42 Correct 24 ms 9600 KB Output is correct
43 Correct 26 ms 9720 KB Output is correct
44 Correct 23 ms 9600 KB Output is correct
45 Correct 25 ms 9600 KB Output is correct
46 Correct 23 ms 9600 KB Output is correct
47 Correct 24 ms 9600 KB Output is correct
48 Correct 25 ms 9728 KB Output is correct
49 Correct 25 ms 9592 KB Output is correct
50 Correct 24 ms 9600 KB Output is correct
51 Correct 47 ms 10488 KB Output is correct
52 Correct 52 ms 10232 KB Output is correct
53 Correct 47 ms 10492 KB Output is correct
54 Correct 48 ms 10232 KB Output is correct
55 Correct 48 ms 10488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8192 KB Output is correct
2 Correct 10 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 10 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8320 KB Output is correct
7 Correct 12 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 9 ms 8192 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
11 Correct 9 ms 8192 KB Output is correct
12 Correct 9 ms 8192 KB Output is correct
13 Correct 10 ms 8192 KB Output is correct
14 Correct 10 ms 8192 KB Output is correct
15 Correct 10 ms 8192 KB Output is correct
16 Correct 10 ms 8192 KB Output is correct
17 Correct 10 ms 8192 KB Output is correct
18 Correct 10 ms 8192 KB Output is correct
19 Correct 10 ms 8192 KB Output is correct
20 Correct 10 ms 8192 KB Output is correct
21 Correct 10 ms 8320 KB Output is correct
22 Correct 10 ms 8192 KB Output is correct
23 Correct 10 ms 8192 KB Output is correct
24 Correct 10 ms 8192 KB Output is correct
25 Correct 10 ms 8192 KB Output is correct
26 Correct 24 ms 9696 KB Output is correct
27 Correct 25 ms 9600 KB Output is correct
28 Correct 24 ms 9600 KB Output is correct
29 Correct 24 ms 9600 KB Output is correct
30 Correct 23 ms 9600 KB Output is correct
31 Correct 45 ms 11124 KB Output is correct
32 Correct 46 ms 11124 KB Output is correct
33 Correct 49 ms 11124 KB Output is correct
34 Correct 45 ms 11128 KB Output is correct
35 Correct 52 ms 11124 KB Output is correct
36 Correct 49 ms 11128 KB Output is correct
37 Correct 50 ms 11128 KB Output is correct
38 Correct 51 ms 11124 KB Output is correct
39 Correct 52 ms 11124 KB Output is correct
40 Correct 52 ms 11124 KB Output is correct
41 Correct 23 ms 9600 KB Output is correct
42 Correct 24 ms 9600 KB Output is correct
43 Correct 26 ms 9720 KB Output is correct
44 Correct 23 ms 9600 KB Output is correct
45 Correct 25 ms 9600 KB Output is correct
46 Correct 23 ms 9600 KB Output is correct
47 Correct 24 ms 9600 KB Output is correct
48 Correct 25 ms 9728 KB Output is correct
49 Correct 25 ms 9592 KB Output is correct
50 Correct 24 ms 9600 KB Output is correct
51 Correct 47 ms 10488 KB Output is correct
52 Correct 52 ms 10232 KB Output is correct
53 Correct 47 ms 10492 KB Output is correct
54 Correct 48 ms 10232 KB Output is correct
55 Correct 48 ms 10488 KB Output is correct
56 Correct 441 ms 27384 KB Output is correct
57 Correct 425 ms 27128 KB Output is correct
58 Correct 423 ms 26104 KB Output is correct
59 Correct 397 ms 26360 KB Output is correct
60 Correct 421 ms 27512 KB Output is correct