Submission #506793

# Submission time Handle Problem Language Result Execution time Memory
506793 2022-01-12T06:57:23 Z abc864197532 Money (IZhO17_money) C++17
100 / 100
219 ms 18776 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define X first
#define Y second
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
	cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
	for (; l != r; ++l)
		cout << *l << " \n"[l + 1 == r];
}
#define test(x...) abc("[" + string(#x) + "]", x);
const int N = 1000001;

int dsu[N];

int Find(int x) {
	if (dsu[x] == x)
		return x;
	return dsu[x] = Find(dsu[x]);
}

void Union(int u, int v) {
	dsu[Find(u)] = Find(v);
}

int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector <int> a(n), cnt(N, 0);
	for (int i = 0; i < n; ++i) {
		cin >> a[i], --a[i], cnt[a[i]]++;
	}
	iota(dsu, dsu + N, 0);
	for (int i = 1; i < N; ++i) if (!cnt[i])
		Union(i, i - 1);
	reverse(all(a));
	int ans = 0;
	for (int i = 0, j = 0; i < n; i = j) {
		ans++;
		if (i + 1 == n) {
			break;
		}
		while (j < n && a[i] == a[j])
			cnt[a[j]]--, j++;
		if (!cnt[a[i]])
			Union(a[i], a[i] - 1);
		int x = Find(a[i] - 1);
		while (j < n) {
			if (x != a[j])
				break;
			cnt[a[j]]--, j++;
			if (!cnt[x])
				Union(x, x - 1), x = Find(x);
		}
	}
	cout << ans << endl;
}
 
/*
6
3 6 4 5 1 2
*/
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 11 ms 8144 KB Output is correct
3 Correct 6 ms 8140 KB Output is correct
4 Correct 7 ms 8140 KB Output is correct
5 Correct 7 ms 8140 KB Output is correct
6 Correct 7 ms 8140 KB Output is correct
7 Correct 9 ms 8148 KB Output is correct
8 Correct 7 ms 8148 KB Output is correct
9 Correct 8 ms 8152 KB Output is correct
10 Correct 7 ms 8140 KB Output is correct
11 Correct 7 ms 8116 KB Output is correct
12 Correct 9 ms 8056 KB Output is correct
13 Correct 9 ms 8140 KB Output is correct
14 Correct 7 ms 8148 KB Output is correct
15 Correct 9 ms 8144 KB Output is correct
16 Correct 7 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 11 ms 8144 KB Output is correct
3 Correct 6 ms 8140 KB Output is correct
4 Correct 7 ms 8140 KB Output is correct
5 Correct 7 ms 8140 KB Output is correct
6 Correct 7 ms 8140 KB Output is correct
7 Correct 9 ms 8148 KB Output is correct
8 Correct 7 ms 8148 KB Output is correct
9 Correct 8 ms 8152 KB Output is correct
10 Correct 7 ms 8140 KB Output is correct
11 Correct 7 ms 8116 KB Output is correct
12 Correct 9 ms 8056 KB Output is correct
13 Correct 9 ms 8140 KB Output is correct
14 Correct 7 ms 8148 KB Output is correct
15 Correct 9 ms 8144 KB Output is correct
16 Correct 7 ms 8140 KB Output is correct
17 Correct 11 ms 8140 KB Output is correct
18 Correct 9 ms 8140 KB Output is correct
19 Correct 8 ms 8148 KB Output is correct
20 Correct 8 ms 8148 KB Output is correct
21 Correct 9 ms 8152 KB Output is correct
22 Correct 6 ms 8140 KB Output is correct
23 Correct 6 ms 8144 KB Output is correct
24 Correct 6 ms 8140 KB Output is correct
25 Correct 6 ms 8144 KB Output is correct
26 Correct 6 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 11 ms 8144 KB Output is correct
3 Correct 6 ms 8140 KB Output is correct
4 Correct 7 ms 8140 KB Output is correct
5 Correct 7 ms 8140 KB Output is correct
6 Correct 7 ms 8140 KB Output is correct
7 Correct 9 ms 8148 KB Output is correct
8 Correct 7 ms 8148 KB Output is correct
9 Correct 8 ms 8152 KB Output is correct
10 Correct 7 ms 8140 KB Output is correct
11 Correct 7 ms 8116 KB Output is correct
12 Correct 9 ms 8056 KB Output is correct
13 Correct 9 ms 8140 KB Output is correct
14 Correct 7 ms 8148 KB Output is correct
15 Correct 9 ms 8144 KB Output is correct
16 Correct 7 ms 8140 KB Output is correct
17 Correct 11 ms 8140 KB Output is correct
18 Correct 9 ms 8140 KB Output is correct
19 Correct 8 ms 8148 KB Output is correct
20 Correct 8 ms 8148 KB Output is correct
21 Correct 9 ms 8152 KB Output is correct
22 Correct 6 ms 8140 KB Output is correct
23 Correct 6 ms 8144 KB Output is correct
24 Correct 6 ms 8140 KB Output is correct
25 Correct 6 ms 8144 KB Output is correct
26 Correct 6 ms 8140 KB Output is correct
27 Correct 6 ms 8064 KB Output is correct
28 Correct 8 ms 8140 KB Output is correct
29 Correct 7 ms 8140 KB Output is correct
30 Correct 7 ms 8140 KB Output is correct
31 Correct 7 ms 8140 KB Output is correct
32 Correct 10 ms 8140 KB Output is correct
33 Correct 7 ms 8140 KB Output is correct
34 Correct 7 ms 8140 KB Output is correct
35 Correct 6 ms 8140 KB Output is correct
36 Correct 6 ms 8140 KB Output is correct
37 Correct 7 ms 8148 KB Output is correct
38 Correct 7 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8140 KB Output is correct
2 Correct 11 ms 8144 KB Output is correct
3 Correct 6 ms 8140 KB Output is correct
4 Correct 7 ms 8140 KB Output is correct
5 Correct 7 ms 8140 KB Output is correct
6 Correct 7 ms 8140 KB Output is correct
7 Correct 9 ms 8148 KB Output is correct
8 Correct 7 ms 8148 KB Output is correct
9 Correct 8 ms 8152 KB Output is correct
10 Correct 7 ms 8140 KB Output is correct
11 Correct 7 ms 8116 KB Output is correct
12 Correct 9 ms 8056 KB Output is correct
13 Correct 9 ms 8140 KB Output is correct
14 Correct 7 ms 8148 KB Output is correct
15 Correct 9 ms 8144 KB Output is correct
16 Correct 7 ms 8140 KB Output is correct
17 Correct 11 ms 8140 KB Output is correct
18 Correct 9 ms 8140 KB Output is correct
19 Correct 8 ms 8148 KB Output is correct
20 Correct 8 ms 8148 KB Output is correct
21 Correct 9 ms 8152 KB Output is correct
22 Correct 6 ms 8140 KB Output is correct
23 Correct 6 ms 8144 KB Output is correct
24 Correct 6 ms 8140 KB Output is correct
25 Correct 6 ms 8144 KB Output is correct
26 Correct 6 ms 8140 KB Output is correct
27 Correct 6 ms 8064 KB Output is correct
28 Correct 8 ms 8140 KB Output is correct
29 Correct 7 ms 8140 KB Output is correct
30 Correct 7 ms 8140 KB Output is correct
31 Correct 7 ms 8140 KB Output is correct
32 Correct 10 ms 8140 KB Output is correct
33 Correct 7 ms 8140 KB Output is correct
34 Correct 7 ms 8140 KB Output is correct
35 Correct 6 ms 8140 KB Output is correct
36 Correct 6 ms 8140 KB Output is correct
37 Correct 7 ms 8148 KB Output is correct
38 Correct 7 ms 8140 KB Output is correct
39 Correct 70 ms 9952 KB Output is correct
40 Correct 87 ms 11224 KB Output is correct
41 Correct 44 ms 9608 KB Output is correct
42 Correct 49 ms 9428 KB Output is correct
43 Correct 29 ms 9044 KB Output is correct
44 Correct 133 ms 11996 KB Output is correct
45 Correct 131 ms 12000 KB Output is correct
46 Correct 96 ms 11984 KB Output is correct
47 Correct 89 ms 12000 KB Output is correct
48 Correct 92 ms 11988 KB Output is correct
49 Correct 169 ms 12048 KB Output is correct
50 Correct 170 ms 11976 KB Output is correct
51 Correct 142 ms 11992 KB Output is correct
52 Correct 131 ms 12048 KB Output is correct
53 Correct 168 ms 11984 KB Output is correct
54 Correct 160 ms 11988 KB Output is correct
55 Correct 167 ms 11984 KB Output is correct
56 Correct 159 ms 12048 KB Output is correct
57 Correct 219 ms 12056 KB Output is correct
58 Correct 157 ms 11972 KB Output is correct
59 Correct 190 ms 18776 KB Output is correct
60 Correct 190 ms 18768 KB Output is correct
61 Correct 149 ms 18764 KB Output is correct
62 Correct 209 ms 18756 KB Output is correct