Submission #402566

# Submission time Handle Problem Language Result Execution time Memory
402566 2021-05-12T00:42:34 Z penguinhacker Exercise Deadlines (CCO20_day1problem2) C++14
25 / 25
309 ms 22748 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

const int mxN=2e5;
int n, a[mxN];
vector<int> oc[mxN];
ll ans;
set<int> s;
tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> t;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> a[i], --a[i];
		oc[a[i]].push_back(i);
	}
	for (int i=n-1; ~i; --i) {
		for (int j : oc[i])
			s.insert(j);
		if (s.empty()) {
			cout << -1;
			return 0;
		}
		int x=*s.rbegin();
		s.erase(--s.end());
		t.insert(x);
		x-=t.order_of_key(x);
		ans+=i-x;
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5352 KB Output is correct
2 Correct 6 ms 5324 KB Output is correct
3 Correct 6 ms 5284 KB Output is correct
4 Correct 6 ms 5324 KB Output is correct
5 Correct 8 ms 5380 KB Output is correct
6 Correct 7 ms 5324 KB Output is correct
7 Correct 8 ms 5416 KB Output is correct
8 Correct 7 ms 5452 KB Output is correct
9 Correct 6 ms 5324 KB Output is correct
10 Correct 6 ms 5452 KB Output is correct
11 Correct 6 ms 5452 KB Output is correct
12 Correct 6 ms 5416 KB Output is correct
13 Correct 7 ms 5324 KB Output is correct
14 Correct 7 ms 5288 KB Output is correct
15 Correct 6 ms 5324 KB Output is correct
16 Correct 8 ms 5388 KB Output is correct
17 Correct 6 ms 5324 KB Output is correct
18 Correct 6 ms 5288 KB Output is correct
19 Correct 7 ms 5324 KB Output is correct
20 Correct 6 ms 5324 KB Output is correct
21 Correct 6 ms 5324 KB Output is correct
22 Correct 8 ms 5284 KB Output is correct
23 Correct 7 ms 5324 KB Output is correct
24 Correct 7 ms 5388 KB Output is correct
25 Correct 7 ms 5324 KB Output is correct
26 Correct 7 ms 5324 KB Output is correct
27 Correct 7 ms 5284 KB Output is correct
28 Correct 6 ms 5324 KB Output is correct
29 Correct 7 ms 5324 KB Output is correct
30 Correct 6 ms 5292 KB Output is correct
31 Correct 5 ms 5248 KB Output is correct
32 Correct 7 ms 5288 KB Output is correct
33 Correct 6 ms 5452 KB Output is correct
34 Correct 6 ms 5324 KB Output is correct
35 Correct 6 ms 5288 KB Output is correct
36 Correct 7 ms 5324 KB Output is correct
37 Correct 6 ms 5452 KB Output is correct
38 Correct 7 ms 5324 KB Output is correct
39 Correct 6 ms 5324 KB Output is correct
40 Correct 6 ms 5284 KB Output is correct
41 Correct 4 ms 5068 KB Output is correct
42 Correct 7 ms 5288 KB Output is correct
43 Correct 4 ms 5160 KB Output is correct
44 Correct 4 ms 4940 KB Output is correct
45 Correct 3 ms 5020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5352 KB Output is correct
2 Correct 6 ms 5324 KB Output is correct
3 Correct 6 ms 5284 KB Output is correct
4 Correct 6 ms 5324 KB Output is correct
5 Correct 8 ms 5380 KB Output is correct
6 Correct 7 ms 5324 KB Output is correct
7 Correct 8 ms 5416 KB Output is correct
8 Correct 7 ms 5452 KB Output is correct
9 Correct 6 ms 5324 KB Output is correct
10 Correct 6 ms 5452 KB Output is correct
11 Correct 6 ms 5452 KB Output is correct
12 Correct 6 ms 5416 KB Output is correct
13 Correct 7 ms 5324 KB Output is correct
14 Correct 7 ms 5288 KB Output is correct
15 Correct 6 ms 5324 KB Output is correct
16 Correct 8 ms 5388 KB Output is correct
17 Correct 6 ms 5324 KB Output is correct
18 Correct 6 ms 5288 KB Output is correct
19 Correct 7 ms 5324 KB Output is correct
20 Correct 6 ms 5324 KB Output is correct
21 Correct 6 ms 5324 KB Output is correct
22 Correct 8 ms 5284 KB Output is correct
23 Correct 7 ms 5324 KB Output is correct
24 Correct 7 ms 5388 KB Output is correct
25 Correct 7 ms 5324 KB Output is correct
26 Correct 7 ms 5324 KB Output is correct
27 Correct 7 ms 5284 KB Output is correct
28 Correct 6 ms 5324 KB Output is correct
29 Correct 7 ms 5324 KB Output is correct
30 Correct 6 ms 5292 KB Output is correct
31 Correct 5 ms 5248 KB Output is correct
32 Correct 7 ms 5288 KB Output is correct
33 Correct 6 ms 5452 KB Output is correct
34 Correct 6 ms 5324 KB Output is correct
35 Correct 6 ms 5288 KB Output is correct
36 Correct 7 ms 5324 KB Output is correct
37 Correct 6 ms 5452 KB Output is correct
38 Correct 7 ms 5324 KB Output is correct
39 Correct 6 ms 5324 KB Output is correct
40 Correct 6 ms 5284 KB Output is correct
41 Correct 4 ms 5068 KB Output is correct
42 Correct 7 ms 5288 KB Output is correct
43 Correct 4 ms 5160 KB Output is correct
44 Correct 4 ms 4940 KB Output is correct
45 Correct 3 ms 5020 KB Output is correct
46 Correct 236 ms 19700 KB Output is correct
47 Correct 240 ms 19636 KB Output is correct
48 Correct 190 ms 19760 KB Output is correct
49 Correct 196 ms 19700 KB Output is correct
50 Correct 208 ms 19652 KB Output is correct
51 Correct 196 ms 19756 KB Output is correct
52 Correct 228 ms 22600 KB Output is correct
53 Correct 230 ms 22748 KB Output is correct
54 Correct 182 ms 22688 KB Output is correct
55 Correct 144 ms 22688 KB Output is correct
56 Correct 230 ms 22592 KB Output is correct
57 Correct 190 ms 22652 KB Output is correct
58 Correct 220 ms 20420 KB Output is correct
59 Correct 246 ms 20420 KB Output is correct
60 Correct 219 ms 20484 KB Output is correct
61 Correct 183 ms 20512 KB Output is correct
62 Correct 150 ms 20372 KB Output is correct
63 Correct 191 ms 20676 KB Output is correct
64 Correct 231 ms 20380 KB Output is correct
65 Correct 226 ms 20392 KB Output is correct
66 Correct 226 ms 20384 KB Output is correct
67 Correct 182 ms 20292 KB Output is correct
68 Correct 203 ms 20404 KB Output is correct
69 Correct 222 ms 20344 KB Output is correct
70 Correct 309 ms 20088 KB Output is correct
71 Correct 221 ms 20088 KB Output is correct
72 Correct 222 ms 20292 KB Output is correct
73 Correct 203 ms 20016 KB Output is correct
74 Correct 174 ms 20036 KB Output is correct
75 Correct 245 ms 20164 KB Output is correct
76 Correct 96 ms 13464 KB Output is correct
77 Correct 146 ms 17460 KB Output is correct
78 Correct 133 ms 22544 KB Output is correct
79 Correct 139 ms 20472 KB Output is correct
80 Correct 130 ms 15452 KB Output is correct
81 Correct 142 ms 17464 KB Output is correct
82 Correct 133 ms 22672 KB Output is correct
83 Correct 138 ms 20400 KB Output is correct
84 Correct 235 ms 20020 KB Output is correct
85 Correct 233 ms 20008 KB Output is correct
86 Correct 229 ms 20040 KB Output is correct
87 Correct 50 ms 10564 KB Output is correct
88 Correct 257 ms 19996 KB Output is correct