码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 42 (Rated for Div. 2) D - Merge Equals

时间:2018-04-16 00:44:07      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:const   inf   \n   als   targe   amp   typedef   for   ati   

这道题我可以直接模拟
理由是一个数*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

标签:const   inf   \n   als   targe   amp   typedef   for   ati   

原文地址:https://www.cnblogs.com/Basasuya/p/8850334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!