Submission #217741

# Submission time Handle Problem Language Result Execution time Memory
217741 2020-03-30T15:08:12 Z quocnguyen1012 Pilot (NOI19_pilot) C++14
100 / 100
489 ms 40580 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 1e6 + 5;

int N, Q, h[maxn];ll res[maxn];
int nl[maxn], nr[maxn];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> Q;
  for(int i = 1; i <= N; ++i)
    cin >> h[i];
  vector<int> st;
  for(int i = 1; i <= N; ++i){
    while(st.size() && h[st.back()] < h[i]) st.pop_back();
    if(st.empty()) nl[i] = 0;
    else nl[i] = st.back();
    st.eb(i);
  }
  st.clear();
  for(int i = N; i >= 1; --i){
    while(st.size() && h[st.back()] <= h[i]) st.pop_back();
    if(st.empty()) nr[i] = N + 1;
    else nr[i] = st.back();
    st.eb(i);
  }
  for(int i = 1; i <= N; ++i){
    res[h[i]] += 1ll * (i - nl[i]) * (nr[i] - i);
  }
  for(int i = 1; i < maxn; ++i)
    res[i] += res[i - 1];
  while(Q--){
    int x; cin >> x;
    cout << res[x] << '\n';
  }
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8320 KB Output is correct
2 Correct 11 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 13 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8192 KB Output is correct
7 Correct 11 ms 8192 KB Output is correct
8 Correct 12 ms 8192 KB Output is correct
9 Correct 11 ms 8192 KB Output is correct
10 Correct 11 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8320 KB Output is correct
2 Correct 11 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 13 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8192 KB Output is correct
7 Correct 11 ms 8192 KB Output is correct
8 Correct 12 ms 8192 KB Output is correct
9 Correct 11 ms 8192 KB Output is correct
10 Correct 11 ms 8192 KB Output is correct
11 Correct 10 ms 8192 KB Output is correct
12 Correct 10 ms 8192 KB Output is correct
13 Correct 11 ms 8192 KB Output is correct
14 Correct 10 ms 8192 KB Output is correct
15 Correct 10 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8320 KB Output is correct
2 Correct 11 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 13 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8192 KB Output is correct
7 Correct 11 ms 8192 KB Output is correct
8 Correct 12 ms 8192 KB Output is correct
9 Correct 11 ms 8192 KB Output is correct
10 Correct 11 ms 8192 KB Output is correct
11 Correct 10 ms 8192 KB Output is correct
12 Correct 10 ms 8192 KB Output is correct
13 Correct 11 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 11 ms 8192 KB Output is correct
17 Correct 11 ms 8192 KB Output is correct
18 Correct 11 ms 8192 KB Output is correct
19 Correct 11 ms 8192 KB Output is correct
20 Correct 11 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8320 KB Output is correct
2 Correct 11 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 13 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8192 KB Output is correct
7 Correct 11 ms 8192 KB Output is correct
8 Correct 12 ms 8192 KB Output is correct
9 Correct 11 ms 8192 KB Output is correct
10 Correct 11 ms 8192 KB Output is correct
11 Correct 10 ms 8192 KB Output is correct
12 Correct 10 ms 8192 KB Output is correct
13 Correct 11 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 11 ms 8192 KB Output is correct
17 Correct 11 ms 8192 KB Output is correct
18 Correct 11 ms 8192 KB Output is correct
19 Correct 11 ms 8192 KB Output is correct
20 Correct 11 ms 8192 KB Output is correct
21 Correct 11 ms 8192 KB Output is correct
22 Correct 11 ms 8192 KB Output is correct
23 Correct 11 ms 8192 KB Output is correct
24 Correct 11 ms 8192 KB Output is correct
25 Correct 11 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 9856 KB Output is correct
2 Correct 28 ms 9984 KB Output is correct
3 Correct 24 ms 9848 KB Output is correct
4 Correct 26 ms 9856 KB Output is correct
5 Correct 25 ms 9856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 11920 KB Output is correct
2 Correct 76 ms 12012 KB Output is correct
3 Correct 51 ms 11940 KB Output is correct
4 Correct 50 ms 12020 KB Output is correct
5 Correct 59 ms 11892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 12020 KB Output is correct
2 Correct 58 ms 12020 KB Output is correct
3 Correct 52 ms 12016 KB Output is correct
4 Correct 60 ms 12148 KB Output is correct
5 Correct 66 ms 12128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8320 KB Output is correct
2 Correct 11 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 13 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8192 KB Output is correct
7 Correct 11 ms 8192 KB Output is correct
8 Correct 12 ms 8192 KB Output is correct
9 Correct 11 ms 8192 KB Output is correct
10 Correct 11 ms 8192 KB Output is correct
11 Correct 26 ms 9856 KB Output is correct
12 Correct 28 ms 9984 KB Output is correct
13 Correct 24 ms 9848 KB Output is correct
14 Correct 26 ms 9856 KB Output is correct
15 Correct 25 ms 9856 KB Output is correct
16 Correct 25 ms 9856 KB Output is correct
17 Correct 28 ms 9960 KB Output is correct
18 Correct 27 ms 9984 KB Output is correct
19 Correct 23 ms 9856 KB Output is correct
20 Correct 29 ms 10112 KB Output is correct
21 Correct 24 ms 9784 KB Output is correct
22 Correct 26 ms 9856 KB Output is correct
23 Correct 28 ms 9984 KB Output is correct
24 Correct 30 ms 9848 KB Output is correct
25 Correct 26 ms 9856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8320 KB Output is correct
2 Correct 11 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 13 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8192 KB Output is correct
7 Correct 11 ms 8192 KB Output is correct
8 Correct 12 ms 8192 KB Output is correct
9 Correct 11 ms 8192 KB Output is correct
10 Correct 11 ms 8192 KB Output is correct
11 Correct 10 ms 8192 KB Output is correct
12 Correct 10 ms 8192 KB Output is correct
13 Correct 11 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 11 ms 8192 KB Output is correct
17 Correct 11 ms 8192 KB Output is correct
18 Correct 11 ms 8192 KB Output is correct
19 Correct 11 ms 8192 KB Output is correct
20 Correct 11 ms 8192 KB Output is correct
21 Correct 11 ms 8192 KB Output is correct
22 Correct 11 ms 8192 KB Output is correct
23 Correct 11 ms 8192 KB Output is correct
24 Correct 11 ms 8192 KB Output is correct
25 Correct 11 ms 8192 KB Output is correct
26 Correct 26 ms 9856 KB Output is correct
27 Correct 28 ms 9984 KB Output is correct
28 Correct 24 ms 9848 KB Output is correct
29 Correct 26 ms 9856 KB Output is correct
30 Correct 25 ms 9856 KB Output is correct
31 Correct 54 ms 11920 KB Output is correct
32 Correct 76 ms 12012 KB Output is correct
33 Correct 51 ms 11940 KB Output is correct
34 Correct 50 ms 12020 KB Output is correct
35 Correct 59 ms 11892 KB Output is correct
36 Correct 51 ms 12020 KB Output is correct
37 Correct 58 ms 12020 KB Output is correct
38 Correct 52 ms 12016 KB Output is correct
39 Correct 60 ms 12148 KB Output is correct
40 Correct 66 ms 12128 KB Output is correct
41 Correct 25 ms 9856 KB Output is correct
42 Correct 28 ms 9960 KB Output is correct
43 Correct 27 ms 9984 KB Output is correct
44 Correct 23 ms 9856 KB Output is correct
45 Correct 29 ms 10112 KB Output is correct
46 Correct 24 ms 9784 KB Output is correct
47 Correct 26 ms 9856 KB Output is correct
48 Correct 28 ms 9984 KB Output is correct
49 Correct 30 ms 9848 KB Output is correct
50 Correct 26 ms 9856 KB Output is correct
51 Correct 54 ms 11256 KB Output is correct
52 Correct 59 ms 11232 KB Output is correct
53 Correct 52 ms 11384 KB Output is correct
54 Correct 59 ms 11256 KB Output is correct
55 Correct 51 ms 11360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8320 KB Output is correct
2 Correct 11 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 13 ms 8192 KB Output is correct
5 Correct 10 ms 8192 KB Output is correct
6 Correct 10 ms 8192 KB Output is correct
7 Correct 11 ms 8192 KB Output is correct
8 Correct 12 ms 8192 KB Output is correct
9 Correct 11 ms 8192 KB Output is correct
10 Correct 11 ms 8192 KB Output is correct
11 Correct 10 ms 8192 KB Output is correct
12 Correct 10 ms 8192 KB Output is correct
13 Correct 11 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 11 ms 8192 KB Output is correct
17 Correct 11 ms 8192 KB Output is correct
18 Correct 11 ms 8192 KB Output is correct
19 Correct 11 ms 8192 KB Output is correct
20 Correct 11 ms 8192 KB Output is correct
21 Correct 11 ms 8192 KB Output is correct
22 Correct 11 ms 8192 KB Output is correct
23 Correct 11 ms 8192 KB Output is correct
24 Correct 11 ms 8192 KB Output is correct
25 Correct 11 ms 8192 KB Output is correct
26 Correct 26 ms 9856 KB Output is correct
27 Correct 28 ms 9984 KB Output is correct
28 Correct 24 ms 9848 KB Output is correct
29 Correct 26 ms 9856 KB Output is correct
30 Correct 25 ms 9856 KB Output is correct
31 Correct 54 ms 11920 KB Output is correct
32 Correct 76 ms 12012 KB Output is correct
33 Correct 51 ms 11940 KB Output is correct
34 Correct 50 ms 12020 KB Output is correct
35 Correct 59 ms 11892 KB Output is correct
36 Correct 51 ms 12020 KB Output is correct
37 Correct 58 ms 12020 KB Output is correct
38 Correct 52 ms 12016 KB Output is correct
39 Correct 60 ms 12148 KB Output is correct
40 Correct 66 ms 12128 KB Output is correct
41 Correct 25 ms 9856 KB Output is correct
42 Correct 28 ms 9960 KB Output is correct
43 Correct 27 ms 9984 KB Output is correct
44 Correct 23 ms 9856 KB Output is correct
45 Correct 29 ms 10112 KB Output is correct
46 Correct 24 ms 9784 KB Output is correct
47 Correct 26 ms 9856 KB Output is correct
48 Correct 28 ms 9984 KB Output is correct
49 Correct 30 ms 9848 KB Output is correct
50 Correct 26 ms 9856 KB Output is correct
51 Correct 54 ms 11256 KB Output is correct
52 Correct 59 ms 11232 KB Output is correct
53 Correct 52 ms 11384 KB Output is correct
54 Correct 59 ms 11256 KB Output is correct
55 Correct 51 ms 11360 KB Output is correct
56 Correct 465 ms 39800 KB Output is correct
57 Correct 459 ms 39800 KB Output is correct
58 Correct 436 ms 37996 KB Output is correct
59 Correct 437 ms 38624 KB Output is correct
60 Correct 489 ms 40580 KB Output is correct