Submission #720114

# Submission time Handle Problem Language Result Execution time Memory
720114 2023-04-07T12:42:46 Z Cyanmond Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 74692 KB
#include <bits/stdc++.h>

using i64 = long long;

i64 c2(i64 x) {
    return x * (x + 1) / 2;
}

void solve() {
    int N, Q;
    std::cin >> N >> Q;
    std::vector<int> H(N), Y(Q);
    for (auto &e : H) std::cin >> e;
    for (auto &e : Y) std::cin >> e;
    std::vector<std::pair<int, int>> queries(Q);
    for (int i = 0; i < Q; ++i) queries[i] = {Y[i], i};
    std::sort(queries.begin(), queries.end());
    std::vector<std::pair<int, int>> mountains(N);
    for (int i = 0; i < N; ++i) mountains[i] = {H[i], i};
    std::sort(mountains.begin(), mountains.end());

    std::set<int> s;
    s.insert(-1);
    int j = 0;
    for (int i = 0; i < N; ++i) s.insert(--s.end(), i);
    s.insert(N);
    std::vector<i64> answer(Q);
    i64 countFlights = 0;
    for (int i = 0; i < N; ++i) {
        while (j != Q and queries[j].first < mountains[i].first) {
            answer[queries[j].second] = countFlights;
            ++j;
        }
        auto itr = s.lower_bound(mountains[i].second);
        const auto m = *itr;
        --itr;
        const auto l = *itr;
        ++itr;
        ++itr;
        const auto r = *itr;
        s.erase(--itr);
        countFlights -= c2(r - m - 1);
        countFlights -= c2(m - l - 1);
        countFlights += c2(r - l - 1);
    }
    while (j != Q) {
        answer[queries[j].second] = countFlights;
        ++j;
    }
    for (const auto e : answer) std::cout << e << '\n';
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 5972 KB Output is correct
2 Correct 54 ms 5972 KB Output is correct
3 Correct 56 ms 5820 KB Output is correct
4 Correct 73 ms 5596 KB Output is correct
5 Correct 52 ms 5764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 8480 KB Output is correct
2 Correct 52 ms 8684 KB Output is correct
3 Correct 54 ms 8468 KB Output is correct
4 Correct 53 ms 8708 KB Output is correct
5 Correct 52 ms 8428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 8596 KB Output is correct
2 Correct 49 ms 8480 KB Output is correct
3 Correct 46 ms 8520 KB Output is correct
4 Correct 49 ms 8848 KB Output is correct
5 Correct 55 ms 8756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 52 ms 5972 KB Output is correct
12 Correct 54 ms 5972 KB Output is correct
13 Correct 56 ms 5820 KB Output is correct
14 Correct 73 ms 5596 KB Output is correct
15 Correct 52 ms 5764 KB Output is correct
16 Correct 49 ms 5716 KB Output is correct
17 Correct 57 ms 6068 KB Output is correct
18 Correct 53 ms 6092 KB Output is correct
19 Correct 46 ms 5692 KB Output is correct
20 Correct 58 ms 5972 KB Output is correct
21 Correct 53 ms 5636 KB Output is correct
22 Correct 49 ms 5748 KB Output is correct
23 Correct 58 ms 6100 KB Output is correct
24 Correct 49 ms 5672 KB Output is correct
25 Correct 52 ms 5936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 52 ms 5972 KB Output is correct
27 Correct 54 ms 5972 KB Output is correct
28 Correct 56 ms 5820 KB Output is correct
29 Correct 73 ms 5596 KB Output is correct
30 Correct 52 ms 5764 KB Output is correct
31 Correct 47 ms 8480 KB Output is correct
32 Correct 52 ms 8684 KB Output is correct
33 Correct 54 ms 8468 KB Output is correct
34 Correct 53 ms 8708 KB Output is correct
35 Correct 52 ms 8428 KB Output is correct
36 Correct 49 ms 8596 KB Output is correct
37 Correct 49 ms 8480 KB Output is correct
38 Correct 46 ms 8520 KB Output is correct
39 Correct 49 ms 8848 KB Output is correct
40 Correct 55 ms 8756 KB Output is correct
41 Correct 49 ms 5716 KB Output is correct
42 Correct 57 ms 6068 KB Output is correct
43 Correct 53 ms 6092 KB Output is correct
44 Correct 46 ms 5692 KB Output is correct
45 Correct 58 ms 5972 KB Output is correct
46 Correct 53 ms 5636 KB Output is correct
47 Correct 49 ms 5748 KB Output is correct
48 Correct 58 ms 6100 KB Output is correct
49 Correct 49 ms 5672 KB Output is correct
50 Correct 52 ms 5936 KB Output is correct
51 Correct 73 ms 8548 KB Output is correct
52 Correct 88 ms 8388 KB Output is correct
53 Correct 78 ms 8684 KB Output is correct
54 Correct 80 ms 8244 KB Output is correct
55 Correct 76 ms 8668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 52 ms 5972 KB Output is correct
27 Correct 54 ms 5972 KB Output is correct
28 Correct 56 ms 5820 KB Output is correct
29 Correct 73 ms 5596 KB Output is correct
30 Correct 52 ms 5764 KB Output is correct
31 Correct 47 ms 8480 KB Output is correct
32 Correct 52 ms 8684 KB Output is correct
33 Correct 54 ms 8468 KB Output is correct
34 Correct 53 ms 8708 KB Output is correct
35 Correct 52 ms 8428 KB Output is correct
36 Correct 49 ms 8596 KB Output is correct
37 Correct 49 ms 8480 KB Output is correct
38 Correct 46 ms 8520 KB Output is correct
39 Correct 49 ms 8848 KB Output is correct
40 Correct 55 ms 8756 KB Output is correct
41 Correct 49 ms 5716 KB Output is correct
42 Correct 57 ms 6068 KB Output is correct
43 Correct 53 ms 6092 KB Output is correct
44 Correct 46 ms 5692 KB Output is correct
45 Correct 58 ms 5972 KB Output is correct
46 Correct 53 ms 5636 KB Output is correct
47 Correct 49 ms 5748 KB Output is correct
48 Correct 58 ms 6100 KB Output is correct
49 Correct 49 ms 5672 KB Output is correct
50 Correct 52 ms 5936 KB Output is correct
51 Correct 73 ms 8548 KB Output is correct
52 Correct 88 ms 8388 KB Output is correct
53 Correct 78 ms 8684 KB Output is correct
54 Correct 80 ms 8244 KB Output is correct
55 Correct 76 ms 8668 KB Output is correct
56 Execution timed out 1086 ms 74692 KB Time limit exceeded
57 Halted 0 ms 0 KB -