Submission #273239

# Submission time Handle Problem Language Result Execution time Memory
273239 2020-08-19T04:33:18 Z 임성재(#5106) Exercise Deadlines (CCO20_day1problem2) C++17
25 / 25
131 ms 13688 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n;
int d[200010];
int p[200010];
vector<int> g[200010];
priority_queue<int> pQ;
int tree[200010];

void update(int i) {
	while(i <= n) {
		tree[i]++;

		i += i & -i;
	}
}

int sum(int i) {
	int ret = 0;

	while(i) {
		ret += tree[i];

		i -= i & -i;
	}

	return ret;
}

int main() {
	fast;

	cin >> n;

	for(int i=1; i<=n; i++) {
		cin >> d[i];

		g[d[i]].eb(i);
	}

	for(int i=n; i>=1; i--) {
		for(auto j : g[i]) {
			pQ.em(j);
		}

		if(pQ.empty()) {
			cout << -1;
			return 0;
		}

		p[i] = pQ.top();
		pQ.pop();
	}

	ll ans = 0;

	for(int i=1; i<=n; i++) {
		update(p[i]);
		ans += i - sum(p[i]);
	}

	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5248 KB Output is correct
2 Correct 5 ms 5248 KB Output is correct
3 Correct 6 ms 5248 KB Output is correct
4 Correct 5 ms 5248 KB Output is correct
5 Correct 5 ms 5248 KB Output is correct
6 Correct 6 ms 5248 KB Output is correct
7 Correct 5 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 5 ms 5248 KB Output is correct
10 Correct 5 ms 5248 KB Output is correct
11 Correct 6 ms 5248 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 7 ms 5220 KB Output is correct
14 Correct 6 ms 5248 KB Output is correct
15 Correct 6 ms 5248 KB Output is correct
16 Correct 7 ms 5248 KB Output is correct
17 Correct 5 ms 5248 KB Output is correct
18 Correct 5 ms 5248 KB Output is correct
19 Correct 5 ms 5248 KB Output is correct
20 Correct 5 ms 5248 KB Output is correct
21 Correct 5 ms 5248 KB Output is correct
22 Correct 6 ms 5280 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 5 ms 5248 KB Output is correct
27 Correct 6 ms 5248 KB Output is correct
28 Correct 7 ms 5248 KB Output is correct
29 Correct 8 ms 5248 KB Output is correct
30 Correct 6 ms 5248 KB Output is correct
31 Correct 6 ms 5120 KB Output is correct
32 Correct 6 ms 5248 KB Output is correct
33 Correct 6 ms 5248 KB Output is correct
34 Correct 9 ms 5248 KB Output is correct
35 Correct 5 ms 5120 KB Output is correct
36 Correct 5 ms 5248 KB Output is correct
37 Correct 4 ms 5248 KB Output is correct
38 Correct 5 ms 5248 KB Output is correct
39 Correct 5 ms 5248 KB Output is correct
40 Correct 5 ms 5248 KB Output is correct
41 Correct 5 ms 5248 KB Output is correct
42 Correct 7 ms 5248 KB Output is correct
43 Correct 6 ms 5120 KB Output is correct
44 Correct 6 ms 4992 KB Output is correct
45 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5248 KB Output is correct
2 Correct 5 ms 5248 KB Output is correct
3 Correct 6 ms 5248 KB Output is correct
4 Correct 5 ms 5248 KB Output is correct
5 Correct 5 ms 5248 KB Output is correct
6 Correct 6 ms 5248 KB Output is correct
7 Correct 5 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 5 ms 5248 KB Output is correct
10 Correct 5 ms 5248 KB Output is correct
11 Correct 6 ms 5248 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 7 ms 5220 KB Output is correct
14 Correct 6 ms 5248 KB Output is correct
15 Correct 6 ms 5248 KB Output is correct
16 Correct 7 ms 5248 KB Output is correct
17 Correct 5 ms 5248 KB Output is correct
18 Correct 5 ms 5248 KB Output is correct
19 Correct 5 ms 5248 KB Output is correct
20 Correct 5 ms 5248 KB Output is correct
21 Correct 5 ms 5248 KB Output is correct
22 Correct 6 ms 5280 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 5 ms 5248 KB Output is correct
27 Correct 6 ms 5248 KB Output is correct
28 Correct 7 ms 5248 KB Output is correct
29 Correct 8 ms 5248 KB Output is correct
30 Correct 6 ms 5248 KB Output is correct
31 Correct 6 ms 5120 KB Output is correct
32 Correct 6 ms 5248 KB Output is correct
33 Correct 6 ms 5248 KB Output is correct
34 Correct 9 ms 5248 KB Output is correct
35 Correct 5 ms 5120 KB Output is correct
36 Correct 5 ms 5248 KB Output is correct
37 Correct 4 ms 5248 KB Output is correct
38 Correct 5 ms 5248 KB Output is correct
39 Correct 5 ms 5248 KB Output is correct
40 Correct 5 ms 5248 KB Output is correct
41 Correct 5 ms 5248 KB Output is correct
42 Correct 7 ms 5248 KB Output is correct
43 Correct 6 ms 5120 KB Output is correct
44 Correct 6 ms 4992 KB Output is correct
45 Correct 4 ms 4992 KB Output is correct
46 Correct 131 ms 11000 KB Output is correct
47 Correct 111 ms 10992 KB Output is correct
48 Correct 96 ms 10992 KB Output is correct
49 Correct 91 ms 11120 KB Output is correct
50 Correct 102 ms 10992 KB Output is correct
51 Correct 105 ms 10988 KB Output is correct
52 Correct 112 ms 13688 KB Output is correct
53 Correct 86 ms 13688 KB Output is correct
54 Correct 69 ms 13688 KB Output is correct
55 Correct 49 ms 13592 KB Output is correct
56 Correct 70 ms 13552 KB Output is correct
57 Correct 67 ms 13676 KB Output is correct
58 Correct 110 ms 11512 KB Output is correct
59 Correct 107 ms 11512 KB Output is correct
60 Correct 103 ms 11512 KB Output is correct
61 Correct 81 ms 11512 KB Output is correct
62 Correct 54 ms 11384 KB Output is correct
63 Correct 72 ms 11512 KB Output is correct
64 Correct 101 ms 11404 KB Output is correct
65 Correct 81 ms 11384 KB Output is correct
66 Correct 93 ms 11416 KB Output is correct
67 Correct 70 ms 11384 KB Output is correct
68 Correct 95 ms 11384 KB Output is correct
69 Correct 119 ms 11412 KB Output is correct
70 Correct 120 ms 11280 KB Output is correct
71 Correct 96 ms 11256 KB Output is correct
72 Correct 83 ms 11256 KB Output is correct
73 Correct 87 ms 11252 KB Output is correct
74 Correct 69 ms 11256 KB Output is correct
75 Correct 82 ms 11256 KB Output is correct
76 Correct 71 ms 9508 KB Output is correct
77 Correct 56 ms 9212 KB Output is correct
78 Correct 46 ms 13664 KB Output is correct
79 Correct 51 ms 11512 KB Output is correct
80 Correct 66 ms 9716 KB Output is correct
81 Correct 61 ms 9452 KB Output is correct
82 Correct 46 ms 13688 KB Output is correct
83 Correct 57 ms 11440 KB Output is correct
84 Correct 106 ms 11256 KB Output is correct
85 Correct 118 ms 11256 KB Output is correct
86 Correct 111 ms 11256 KB Output is correct
87 Correct 72 ms 9464 KB Output is correct
88 Correct 115 ms 11384 KB Output is correct