Submission #720113

# Submission time Handle Problem Language Result Execution time Memory
720113 2023-04-07T12:40:24 Z Cyanmond Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 74800 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);
        auto itrL = itr;
        --itrL;
        auto itrR = itr;
        ++itrR;
        countFlights -= c2(*itrR - *itr - 1);
        countFlights -= c2(*itr - *itrL - 1);
        countFlights += c2(*itrR - *itrL - 1);
        s.erase(itr);
    }
    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 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 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 340 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 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 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 340 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 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 6076 KB Output is correct
2 Correct 56 ms 6224 KB Output is correct
3 Correct 47 ms 5944 KB Output is correct
4 Correct 48 ms 5828 KB Output is correct
5 Correct 52 ms 5876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 8652 KB Output is correct
2 Correct 46 ms 8712 KB Output is correct
3 Correct 44 ms 8652 KB Output is correct
4 Correct 53 ms 8884 KB Output is correct
5 Correct 48 ms 8600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 8740 KB Output is correct
2 Correct 48 ms 8628 KB Output is correct
3 Correct 52 ms 8620 KB Output is correct
4 Correct 47 ms 9016 KB Output is correct
5 Correct 47 ms 8892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 54 ms 6076 KB Output is correct
12 Correct 56 ms 6224 KB Output is correct
13 Correct 47 ms 5944 KB Output is correct
14 Correct 48 ms 5828 KB Output is correct
15 Correct 52 ms 5876 KB Output is correct
16 Correct 56 ms 5868 KB Output is correct
17 Correct 51 ms 6192 KB Output is correct
18 Correct 52 ms 6228 KB Output is correct
19 Correct 46 ms 5716 KB Output is correct
20 Correct 54 ms 6084 KB Output is correct
21 Correct 51 ms 5760 KB Output is correct
22 Correct 60 ms 5876 KB Output is correct
23 Correct 50 ms 6228 KB Output is correct
24 Correct 49 ms 5716 KB Output is correct
25 Correct 49 ms 6092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 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 340 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 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 54 ms 6076 KB Output is correct
27 Correct 56 ms 6224 KB Output is correct
28 Correct 47 ms 5944 KB Output is correct
29 Correct 48 ms 5828 KB Output is correct
30 Correct 52 ms 5876 KB Output is correct
31 Correct 43 ms 8652 KB Output is correct
32 Correct 46 ms 8712 KB Output is correct
33 Correct 44 ms 8652 KB Output is correct
34 Correct 53 ms 8884 KB Output is correct
35 Correct 48 ms 8600 KB Output is correct
36 Correct 44 ms 8740 KB Output is correct
37 Correct 48 ms 8628 KB Output is correct
38 Correct 52 ms 8620 KB Output is correct
39 Correct 47 ms 9016 KB Output is correct
40 Correct 47 ms 8892 KB Output is correct
41 Correct 56 ms 5868 KB Output is correct
42 Correct 51 ms 6192 KB Output is correct
43 Correct 52 ms 6228 KB Output is correct
44 Correct 46 ms 5716 KB Output is correct
45 Correct 54 ms 6084 KB Output is correct
46 Correct 51 ms 5760 KB Output is correct
47 Correct 60 ms 5876 KB Output is correct
48 Correct 50 ms 6228 KB Output is correct
49 Correct 49 ms 5716 KB Output is correct
50 Correct 49 ms 6092 KB Output is correct
51 Correct 72 ms 8720 KB Output is correct
52 Correct 92 ms 8500 KB Output is correct
53 Correct 74 ms 8760 KB Output is correct
54 Correct 76 ms 8456 KB Output is correct
55 Correct 76 ms 8836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 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 340 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 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 54 ms 6076 KB Output is correct
27 Correct 56 ms 6224 KB Output is correct
28 Correct 47 ms 5944 KB Output is correct
29 Correct 48 ms 5828 KB Output is correct
30 Correct 52 ms 5876 KB Output is correct
31 Correct 43 ms 8652 KB Output is correct
32 Correct 46 ms 8712 KB Output is correct
33 Correct 44 ms 8652 KB Output is correct
34 Correct 53 ms 8884 KB Output is correct
35 Correct 48 ms 8600 KB Output is correct
36 Correct 44 ms 8740 KB Output is correct
37 Correct 48 ms 8628 KB Output is correct
38 Correct 52 ms 8620 KB Output is correct
39 Correct 47 ms 9016 KB Output is correct
40 Correct 47 ms 8892 KB Output is correct
41 Correct 56 ms 5868 KB Output is correct
42 Correct 51 ms 6192 KB Output is correct
43 Correct 52 ms 6228 KB Output is correct
44 Correct 46 ms 5716 KB Output is correct
45 Correct 54 ms 6084 KB Output is correct
46 Correct 51 ms 5760 KB Output is correct
47 Correct 60 ms 5876 KB Output is correct
48 Correct 50 ms 6228 KB Output is correct
49 Correct 49 ms 5716 KB Output is correct
50 Correct 49 ms 6092 KB Output is correct
51 Correct 72 ms 8720 KB Output is correct
52 Correct 92 ms 8500 KB Output is correct
53 Correct 74 ms 8760 KB Output is correct
54 Correct 76 ms 8456 KB Output is correct
55 Correct 76 ms 8836 KB Output is correct
56 Execution timed out 1086 ms 74800 KB Time limit exceeded
57 Halted 0 ms 0 KB -