Skip to content

Commit

Permalink
20240525 InHng's submission for CF962D (Yawn-Sean#2844)
Browse files Browse the repository at this point in the history
  • Loading branch information
InHng authored May 25, 2024
1 parent ee8bcf5 commit 686452b
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions daily_problems/2024/05/0525/personal_submission/cf962d_inhng.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define endl '\n'
#define int long long
#define lowbit(x) x & -x
#define PII pair<int, int>
#define PIII pair<int, PII>

const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7; // 998244353;

void solve() {
int n;
cin >> n;
map<int, vector<int>> mp;
vector<int> a(n + 1), ans;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
mp[a[i] >> __builtin_ctzll(a[i])].emplace_back(i);
}
// for (auto [_, it] : mp) {
for (map<int, vector<int>>::iterator it = mp.begin(); it != mp.end(); ++it) {
map<int, int> idx;
// for (int i : it) {
for (int i : it->ss) {
if (idx[a[i]]) {
while (idx[a[i]]) {
a[idx[a[i]]] = 0;
idx.erase(a[i]);
a[i] <<= 1;
}
idx[a[i]] = i;
} else {
idx[a[i]] = i;
}
}
}
for (int ai : a) {
if (ai) {
ans.emplace_back(ai);
}
}
cout << ans.size() << endl;
for (int ai : ans) {
cout << ai << " \n"[ai == ans.back()];
}
}

signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(15);
time_t begin = clock();
solve();
time_t end = clock();
double solve_time = double(end - begin) / CLOCKS_PER_SEC;
// cout << "runtime: " << solve_time << endl;
return 0;
}

0 comments on commit 686452b

Please sign in to comment.