forked from Yawn-Sean/Daily_CF_Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20240525 InHng's submission for CF962D (Yawn-Sean#2844)
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
daily_problems/2024/05/0525/personal_submission/cf962d_inhng.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |