Submission #268286

# Submission time Handle Problem Language Result Execution time Memory
268286 2020-08-16T11:00:10 Z imeimi2000 Exercise Deadlines (CCO20_day1problem2) C++17
25 / 25
157 ms 14844 KB
#include <bits/stdc++.h>

using namespace std;

int n;
int D[200001];
vector<int> L[200001];
int R[200001];

int fen[200001];
void update(int i) {
    while (i <= n) {
        ++fen[i];
        i += i & -i;
    }
}

int query(int i) {
    int ret = 0;
    while (i) {
        ret += fen[i];
        i -= i & -i;
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> D[i], L[D[i]].push_back(i);
    priority_queue<int> pq;
    long long ans = 0;
    for (int i = n; i > 0; --i) {
        for (int j : L[i]) pq.push(j);
        if (pq.empty()) {
            printf("-1\n");
            return 0;
        }
        R[i] = pq.top(); pq.pop();
        ans += query(R[i]);
        update(R[i]);
    }
    printf("%lld\n", ans);
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5248 KB Output is correct
2 Correct 7 ms 5248 KB Output is correct
3 Correct 7 ms 5248 KB Output is correct
4 Correct 6 ms 5248 KB Output is correct
5 Correct 6 ms 5248 KB Output is correct
6 Correct 6 ms 5248 KB Output is correct
7 Correct 6 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 6 ms 5248 KB Output is correct
10 Correct 6 ms 5248 KB Output is correct
11 Correct 6 ms 5248 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 5 ms 5248 KB Output is correct
14 Correct 5 ms 5248 KB Output is correct
15 Correct 6 ms 5248 KB Output is correct
16 Correct 6 ms 5248 KB Output is correct
17 Correct 6 ms 5248 KB Output is correct
18 Correct 6 ms 5248 KB Output is correct
19 Correct 5 ms 5248 KB Output is correct
20 Correct 6 ms 5248 KB Output is correct
21 Correct 6 ms 5248 KB Output is correct
22 Correct 6 ms 5248 KB Output is correct
23 Correct 6 ms 5248 KB Output is correct
24 Correct 6 ms 5248 KB Output is correct
25 Correct 5 ms 5248 KB Output is correct
26 Correct 6 ms 5228 KB Output is correct
27 Correct 5 ms 5248 KB Output is correct
28 Correct 5 ms 5248 KB Output is correct
29 Correct 5 ms 5248 KB Output is correct
30 Correct 5 ms 5248 KB Output is correct
31 Correct 6 ms 5248 KB Output is correct
32 Correct 5 ms 5248 KB Output is correct
33 Correct 5 ms 5248 KB Output is correct
34 Correct 6 ms 5248 KB Output is correct
35 Correct 6 ms 5248 KB Output is correct
36 Correct 5 ms 5248 KB Output is correct
37 Correct 6 ms 5248 KB Output is correct
38 Correct 6 ms 5248 KB Output is correct
39 Correct 5 ms 5248 KB Output is correct
40 Correct 6 ms 5248 KB Output is correct
41 Correct 5 ms 5120 KB Output is correct
42 Correct 6 ms 5248 KB Output is correct
43 Correct 6 ms 5120 KB Output is correct
44 Correct 4 ms 4992 KB Output is correct
45 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5248 KB Output is correct
2 Correct 7 ms 5248 KB Output is correct
3 Correct 7 ms 5248 KB Output is correct
4 Correct 6 ms 5248 KB Output is correct
5 Correct 6 ms 5248 KB Output is correct
6 Correct 6 ms 5248 KB Output is correct
7 Correct 6 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 6 ms 5248 KB Output is correct
10 Correct 6 ms 5248 KB Output is correct
11 Correct 6 ms 5248 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 5 ms 5248 KB Output is correct
14 Correct 5 ms 5248 KB Output is correct
15 Correct 6 ms 5248 KB Output is correct
16 Correct 6 ms 5248 KB Output is correct
17 Correct 6 ms 5248 KB Output is correct
18 Correct 6 ms 5248 KB Output is correct
19 Correct 5 ms 5248 KB Output is correct
20 Correct 6 ms 5248 KB Output is correct
21 Correct 6 ms 5248 KB Output is correct
22 Correct 6 ms 5248 KB Output is correct
23 Correct 6 ms 5248 KB Output is correct
24 Correct 6 ms 5248 KB Output is correct
25 Correct 5 ms 5248 KB Output is correct
26 Correct 6 ms 5228 KB Output is correct
27 Correct 5 ms 5248 KB Output is correct
28 Correct 5 ms 5248 KB Output is correct
29 Correct 5 ms 5248 KB Output is correct
30 Correct 5 ms 5248 KB Output is correct
31 Correct 6 ms 5248 KB Output is correct
32 Correct 5 ms 5248 KB Output is correct
33 Correct 5 ms 5248 KB Output is correct
34 Correct 6 ms 5248 KB Output is correct
35 Correct 6 ms 5248 KB Output is correct
36 Correct 5 ms 5248 KB Output is correct
37 Correct 6 ms 5248 KB Output is correct
38 Correct 6 ms 5248 KB Output is correct
39 Correct 5 ms 5248 KB Output is correct
40 Correct 6 ms 5248 KB Output is correct
41 Correct 5 ms 5120 KB Output is correct
42 Correct 6 ms 5248 KB Output is correct
43 Correct 6 ms 5120 KB Output is correct
44 Correct 4 ms 4992 KB Output is correct
45 Correct 4 ms 4992 KB Output is correct
46 Correct 100 ms 12396 KB Output is correct
47 Correct 105 ms 12400 KB Output is correct
48 Correct 90 ms 12400 KB Output is correct
49 Correct 82 ms 12400 KB Output is correct
50 Correct 85 ms 12400 KB Output is correct
51 Correct 82 ms 12420 KB Output is correct
52 Correct 80 ms 14840 KB Output is correct
53 Correct 93 ms 14840 KB Output is correct
54 Correct 73 ms 14844 KB Output is correct
55 Correct 52 ms 14840 KB Output is correct
56 Correct 68 ms 14840 KB Output is correct
57 Correct 74 ms 14840 KB Output is correct
58 Correct 117 ms 12664 KB Output is correct
59 Correct 116 ms 12664 KB Output is correct
60 Correct 86 ms 12732 KB Output is correct
61 Correct 97 ms 12664 KB Output is correct
62 Correct 53 ms 12664 KB Output is correct
63 Correct 93 ms 12664 KB Output is correct
64 Correct 101 ms 12664 KB Output is correct
65 Correct 118 ms 12536 KB Output is correct
66 Correct 102 ms 12580 KB Output is correct
67 Correct 79 ms 12596 KB Output is correct
68 Correct 137 ms 12540 KB Output is correct
69 Correct 112 ms 12664 KB Output is correct
70 Correct 96 ms 12536 KB Output is correct
71 Correct 119 ms 12540 KB Output is correct
72 Correct 92 ms 12536 KB Output is correct
73 Correct 99 ms 12536 KB Output is correct
74 Correct 64 ms 12536 KB Output is correct
75 Correct 90 ms 12536 KB Output is correct
76 Correct 66 ms 11684 KB Output is correct
77 Correct 63 ms 10620 KB Output is correct
78 Correct 59 ms 14840 KB Output is correct
79 Correct 53 ms 12664 KB Output is correct
80 Correct 104 ms 11892 KB Output is correct
81 Correct 59 ms 10732 KB Output is correct
82 Correct 66 ms 14840 KB Output is correct
83 Correct 57 ms 12664 KB Output is correct
84 Correct 95 ms 12660 KB Output is correct
85 Correct 116 ms 12676 KB Output is correct
86 Correct 99 ms 12664 KB Output is correct
87 Correct 61 ms 10744 KB Output is correct
88 Correct 157 ms 12540 KB Output is correct