Submission #225119

# Submission time Handle Problem Language Result Execution time Memory
225119 2020-04-19T09:37:16 Z tictaccat Pilot (NOI19_pilot) C++14
100 / 100
756 ms 56216 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int N,Q;
int H[2000000], l[2000000], r[2000000];
LL ans[2000000];
vector<pair<int,int>> QU, M;

LL pairs(LL n) {
    return n*(n-1)/2 + n;
}

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> Q;
    for (int i = 0; i < N; i++) {
        cin >> H[i];
        M.emplace_back(H[i],i);
        l[i] = i+1;
        r[i] = i-1;
    }
    for (int i = 0; i < Q; i++) {
        int y; 
        cin >> y;
        QU.emplace_back(y,i);
    }

    sort(QU.begin(), QU.end());
    sort(M.begin(), M.end());
    int k = 0;
    LL cnt = 0;

    for (auto m: M) {
        int h,i;
        tie(h,i) = m;
        while (k < Q && QU[k].first < h) {
            ans[QU[k].second] = cnt;
            k++;
        }
        cnt += pairs(r[i]-l[i]-1);
        cnt -= pairs(r[i]-i-1);
        cnt -= pairs(i-l[i]-1);
        if (l[i] != -1) {
            l[r[i]] = l[i];
        }
        if (r[i] != N) {
            r[l[i]] = r[i];            
        }
    }

    while (k < Q) {
        ans[QU[k].second] = cnt;
        k++;
    }

    for (int i = 0; i < Q; i++) cout << ans[i] << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2428 KB Output is correct
2 Correct 28 ms 2424 KB Output is correct
3 Correct 27 ms 2300 KB Output is correct
4 Correct 27 ms 2300 KB Output is correct
5 Correct 27 ms 2300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 4716 KB Output is correct
2 Correct 50 ms 4848 KB Output is correct
3 Correct 51 ms 4848 KB Output is correct
4 Correct 52 ms 4852 KB Output is correct
5 Correct 61 ms 4720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 4724 KB Output is correct
2 Correct 52 ms 4716 KB Output is correct
3 Correct 54 ms 4844 KB Output is correct
4 Correct 54 ms 4828 KB Output is correct
5 Correct 55 ms 5028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 30 ms 2428 KB Output is correct
12 Correct 28 ms 2424 KB Output is correct
13 Correct 27 ms 2300 KB Output is correct
14 Correct 27 ms 2300 KB Output is correct
15 Correct 27 ms 2300 KB Output is correct
16 Correct 28 ms 2300 KB Output is correct
17 Correct 29 ms 2424 KB Output is correct
18 Correct 30 ms 2424 KB Output is correct
19 Correct 27 ms 2300 KB Output is correct
20 Correct 30 ms 2424 KB Output is correct
21 Correct 28 ms 2300 KB Output is correct
22 Correct 28 ms 2300 KB Output is correct
23 Correct 30 ms 2424 KB Output is correct
24 Correct 30 ms 2300 KB Output is correct
25 Correct 29 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 30 ms 2428 KB Output is correct
27 Correct 28 ms 2424 KB Output is correct
28 Correct 27 ms 2300 KB Output is correct
29 Correct 27 ms 2300 KB Output is correct
30 Correct 27 ms 2300 KB Output is correct
31 Correct 48 ms 4716 KB Output is correct
32 Correct 50 ms 4848 KB Output is correct
33 Correct 51 ms 4848 KB Output is correct
34 Correct 52 ms 4852 KB Output is correct
35 Correct 61 ms 4720 KB Output is correct
36 Correct 57 ms 4724 KB Output is correct
37 Correct 52 ms 4716 KB Output is correct
38 Correct 54 ms 4844 KB Output is correct
39 Correct 54 ms 4828 KB Output is correct
40 Correct 55 ms 5028 KB Output is correct
41 Correct 28 ms 2300 KB Output is correct
42 Correct 29 ms 2424 KB Output is correct
43 Correct 30 ms 2424 KB Output is correct
44 Correct 27 ms 2300 KB Output is correct
45 Correct 30 ms 2424 KB Output is correct
46 Correct 28 ms 2300 KB Output is correct
47 Correct 28 ms 2300 KB Output is correct
48 Correct 30 ms 2424 KB Output is correct
49 Correct 30 ms 2300 KB Output is correct
50 Correct 29 ms 2424 KB Output is correct
51 Correct 63 ms 4744 KB Output is correct
52 Correct 68 ms 4504 KB Output is correct
53 Correct 63 ms 4720 KB Output is correct
54 Correct 61 ms 4464 KB Output is correct
55 Correct 66 ms 4692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 30 ms 2428 KB Output is correct
27 Correct 28 ms 2424 KB Output is correct
28 Correct 27 ms 2300 KB Output is correct
29 Correct 27 ms 2300 KB Output is correct
30 Correct 27 ms 2300 KB Output is correct
31 Correct 48 ms 4716 KB Output is correct
32 Correct 50 ms 4848 KB Output is correct
33 Correct 51 ms 4848 KB Output is correct
34 Correct 52 ms 4852 KB Output is correct
35 Correct 61 ms 4720 KB Output is correct
36 Correct 57 ms 4724 KB Output is correct
37 Correct 52 ms 4716 KB Output is correct
38 Correct 54 ms 4844 KB Output is correct
39 Correct 54 ms 4828 KB Output is correct
40 Correct 55 ms 5028 KB Output is correct
41 Correct 28 ms 2300 KB Output is correct
42 Correct 29 ms 2424 KB Output is correct
43 Correct 30 ms 2424 KB Output is correct
44 Correct 27 ms 2300 KB Output is correct
45 Correct 30 ms 2424 KB Output is correct
46 Correct 28 ms 2300 KB Output is correct
47 Correct 28 ms 2300 KB Output is correct
48 Correct 30 ms 2424 KB Output is correct
49 Correct 30 ms 2300 KB Output is correct
50 Correct 29 ms 2424 KB Output is correct
51 Correct 63 ms 4744 KB Output is correct
52 Correct 68 ms 4504 KB Output is correct
53 Correct 63 ms 4720 KB Output is correct
54 Correct 61 ms 4464 KB Output is correct
55 Correct 66 ms 4692 KB Output is correct
56 Correct 691 ms 41980 KB Output is correct
57 Correct 682 ms 54380 KB Output is correct
58 Correct 638 ms 51620 KB Output is correct
59 Correct 657 ms 52780 KB Output is correct
60 Correct 756 ms 56216 KB Output is correct