#include <iostream>
#include <vector>
#define N 5000000
using namespace std;
void update_vec(vector<bool> &v, int &ans, int ai);
int main() {
int n, tmp;
int answer = 0;
vector<bool> vec(N, false);
std::ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tmp;
update_vec(vec, answer, tmp);
}
cout << answer << endl;
}
void update_vec(vector<bool> &v, int &ans, int ai) {
if (v[ai]) {
v[ai] = false;
update_vec(v, ans, ai+1);
} else {
v[ai] = true;
ans = ans > ai? ans : ai;
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <iostream> #include <vector> #define N 5000000 using namespace std; void update_vec(vector<bool> &v, int &ans, int ai); int main() { int n, tmp; int answer = 0; vector<bool> vec(N, false); std::ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> tmp; update_vec(vec, answer, tmp); } cout << answer << endl; } void update_vec(vector<bool> &v, int &ans, int ai) { if (v[ai]) { v[ai] = false; update_vec(v, ans, ai+1); } else { v[ai] = true; ans = ans > ai? ans : ai; } } |
English