Submission #225118

# Submission time Handle Problem Language Result Execution time Memory
225118 2020-04-19T09:36:40 Z tictaccat Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 41124 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 >> 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 4 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 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 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 4 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 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 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 5 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 4 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 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 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 5 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 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 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 4 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 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 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 5 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 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 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 6 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 2488 KB Output is correct
2 Correct 65 ms 2412 KB Output is correct
3 Correct 56 ms 2408 KB Output is correct
4 Correct 58 ms 2296 KB Output is correct
5 Correct 56 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 4720 KB Output is correct
2 Correct 112 ms 5992 KB Output is correct
3 Correct 107 ms 5868 KB Output is correct
4 Correct 110 ms 5988 KB Output is correct
5 Correct 111 ms 5860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 4840 KB Output is correct
2 Correct 118 ms 6016 KB Output is correct
3 Correct 122 ms 5988 KB Output is correct
4 Correct 117 ms 6120 KB Output is correct
5 Correct 122 ms 6248 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 4 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 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 59 ms 2488 KB Output is correct
12 Correct 65 ms 2412 KB Output is correct
13 Correct 56 ms 2408 KB Output is correct
14 Correct 58 ms 2296 KB Output is correct
15 Correct 56 ms 2296 KB Output is correct
16 Correct 56 ms 2288 KB Output is correct
17 Correct 61 ms 2412 KB Output is correct
18 Correct 64 ms 2412 KB Output is correct
19 Correct 56 ms 2288 KB Output is correct
20 Correct 60 ms 2296 KB Output is correct
21 Correct 54 ms 2288 KB Output is correct
22 Correct 60 ms 2288 KB Output is correct
23 Correct 59 ms 2408 KB Output is correct
24 Correct 59 ms 2288 KB Output is correct
25 Correct 59 ms 2288 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 4 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 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 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 5 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 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 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 6 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 59 ms 2488 KB Output is correct
27 Correct 65 ms 2412 KB Output is correct
28 Correct 56 ms 2408 KB Output is correct
29 Correct 58 ms 2296 KB Output is correct
30 Correct 56 ms 2296 KB Output is correct
31 Correct 107 ms 4720 KB Output is correct
32 Correct 112 ms 5992 KB Output is correct
33 Correct 107 ms 5868 KB Output is correct
34 Correct 110 ms 5988 KB Output is correct
35 Correct 111 ms 5860 KB Output is correct
36 Correct 113 ms 4840 KB Output is correct
37 Correct 118 ms 6016 KB Output is correct
38 Correct 122 ms 5988 KB Output is correct
39 Correct 117 ms 6120 KB Output is correct
40 Correct 122 ms 6248 KB Output is correct
41 Correct 56 ms 2288 KB Output is correct
42 Correct 61 ms 2412 KB Output is correct
43 Correct 64 ms 2412 KB Output is correct
44 Correct 56 ms 2288 KB Output is correct
45 Correct 60 ms 2296 KB Output is correct
46 Correct 54 ms 2288 KB Output is correct
47 Correct 60 ms 2288 KB Output is correct
48 Correct 59 ms 2408 KB Output is correct
49 Correct 59 ms 2288 KB Output is correct
50 Correct 59 ms 2288 KB Output is correct
51 Correct 121 ms 5864 KB Output is correct
52 Correct 128 ms 5828 KB Output is correct
53 Correct 122 ms 5864 KB Output is correct
54 Correct 125 ms 5736 KB Output is correct
55 Correct 121 ms 5864 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 4 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 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 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 5 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 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 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 6 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 59 ms 2488 KB Output is correct
27 Correct 65 ms 2412 KB Output is correct
28 Correct 56 ms 2408 KB Output is correct
29 Correct 58 ms 2296 KB Output is correct
30 Correct 56 ms 2296 KB Output is correct
31 Correct 107 ms 4720 KB Output is correct
32 Correct 112 ms 5992 KB Output is correct
33 Correct 107 ms 5868 KB Output is correct
34 Correct 110 ms 5988 KB Output is correct
35 Correct 111 ms 5860 KB Output is correct
36 Correct 113 ms 4840 KB Output is correct
37 Correct 118 ms 6016 KB Output is correct
38 Correct 122 ms 5988 KB Output is correct
39 Correct 117 ms 6120 KB Output is correct
40 Correct 122 ms 6248 KB Output is correct
41 Correct 56 ms 2288 KB Output is correct
42 Correct 61 ms 2412 KB Output is correct
43 Correct 64 ms 2412 KB Output is correct
44 Correct 56 ms 2288 KB Output is correct
45 Correct 60 ms 2296 KB Output is correct
46 Correct 54 ms 2288 KB Output is correct
47 Correct 60 ms 2288 KB Output is correct
48 Correct 59 ms 2408 KB Output is correct
49 Correct 59 ms 2288 KB Output is correct
50 Correct 59 ms 2288 KB Output is correct
51 Correct 121 ms 5864 KB Output is correct
52 Correct 128 ms 5828 KB Output is correct
53 Correct 122 ms 5864 KB Output is correct
54 Correct 125 ms 5736 KB Output is correct
55 Correct 121 ms 5864 KB Output is correct
56 Execution timed out 1081 ms 41124 KB Time limit exceeded
57 Halted 0 ms 0 KB -