Educational Codeforces Round 42 (Rated for Div. 2) D - Merge Equals
Posted basasuya
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 42 (Rated for Div. 2) D - Merge Equals相关的知识,希望对你有一定的参考价值。
这道题我可以直接模拟
理由是一个数*2的过程中最多30次左右
2^31 = 2e9
所以我可以从小的书开始模拟这个过程
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
typedef long long ll;
const int N = 150005;
const int INF = 0x3f3f3f3f;
int A[N];
std::map<ll, std::set<int> > mp;
std::map<int, ll> ans;
int main() {
int n;
while(~scanf("%d", &n)) {
mp.clear();
ans.clear();
for(int i = 0; i < n; ++i) scanf("%d", &A[i]);
for(int i = 0; i < n; ++i) {
mp[A[i]].insert(i);
}
for(auto i = mp.begin(); i != mp.end(); ++i) {
std::set<int> &target = i->second;
int cnt = 0; int last;
for(auto j = target.begin(); j != target.end(); ++j) {
cnt ++;
if(cnt % 2 == 0) {
mp[i->first * 2].insert(*j);
}
last = *j;
}
if(cnt % 2) ans[last] = i->first;
}
printf("%d\n", (int)ans.size());
for(auto i = ans.begin(); i != ans.end(); ++i) {
printf("%lld ", i->second);
}
printf("\n");
}
return 0;
}
以上是关于Educational Codeforces Round 42 (Rated for Div. 2) D - Merge Equals的主要内容,如果未能解决你的问题,请参考以下文章
Educational Codeforces Round 7 A
Educational Codeforces Round 7
Educational Codeforces Round 90
Educational Codeforces Round 33