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

2017 ICPC 南宁 L 带权最值费递减序列

时间:2017-09-25 00:52:35      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:log   using   mat   return   ==   ret   icpc   while   c++   

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int maxm = 800005;
int h[maxm], num[maxn];
int n, m;
int lowbit(int x)
{
        return x & (-x);
}
void update(int x)
{
        while (x <= n)
        {
                h[x] = num[x];
                for (int i = 1; i < lowbit(x); i <<= 1)
                {
                        h[x] = max(h[x], h[x - i]);
                }
                x += lowbit(x);
        }
        return ;
}
int findans(int begin, int end)
{
        int ans = 0;
        while (end >= begin)
        {
                ans = max(ans, num[end]);
                end--;
                for (; end - lowbit(end) >= begin; end -= lowbit(end))
                {
                        ans = max(ans, h[end]);
                }
        }
        return ans;
}
int main()
{
        n=200005;
        int ans = -1;
        int teshu = 0;
        int now;
        memset(h, 0, sizeof(h));
        while (scanf("%d", &now) != EOF)
        {
                if (now < 0)
                {
                        continue;
                }
                if (now >= 10000)
                {
                        now %= 10000;
                        if (now == 0)
                        {
                                teshu += 5;
                        }
                        else
                        {
                                int cur = max(findans(1, now), teshu) + 5;
                                ans = max(ans, cur);
                                num[now] = cur;
                                update(now);
                        }
                }
                else
                {
                        if (now == 0)
                        {
                                teshu += 5;
                        }
                        else
                        {
                                int cur = max(findans(1, now), teshu) + 1;
                                ans = max(ans, cur);
                                num[now] = cur;
                                update(now);
                        }
                }
        }
        cout<<ans<<endl;
        return 0;
}

 

2017 ICPC 南宁 L 带权最值费递减序列

标签:log   using   mat   return   ==   ret   icpc   while   c++   

原文地址:http://www.cnblogs.com/Aragaki/p/7589366.html

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