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

#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;
}
时间: 2024-08-10 19:00:25

2017 ICPC 南宁 L 带权最值费递减序列的相关文章

2017 icpc 南宁网络赛

2000年台湾大专题...英语阅读输入输出专场..我只能说很强势.. M. Frequent Subsets Problem The frequent subset problem is defined as follows. Suppose UU={1, 2,\ldots-,N} is the universe, and S_{1}S?1??, S_{2}S?2??,\ldots-,S_{M}S?M?? are MM sets over UU. Given a positive constan

2017 ACM/ICPC 新疆赛区 I 题 A Possible Tree 带权并查集

传送门 题意:给定一棵带权树的形态, 但是并不知道每天条边的具体权重. 然后给m个信息, 信息格式为u v val, 表示在树上u 到 v 的路径上经过的边的权重的异或和为val, 问前面最多有多少个信息是不冲突的. 思路:首先很明显的我们要维护一系列不知道的信息, 看冲不冲突的那就是带权并查集没跑了, 此时r[v] 表示v到这棵树的根节点(虽然题目没给, 但是我们可以假设一个)的路径异或和, 那么此时的每条信息相当于是告诉你r[u] ^ r[v]的值, 注意异或的特性. 所以对于每条信息维护好

nyoj-----284坦克大战(带权值的图搜索)

坦克大战 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 Many of us had played the game "Battle city" in our childhood, and some people (like me) even often play it on computer now. What we are discussing is a simple edition of this game. Given a map that co

HDU 1863:畅通工程(带权值的并查集)

畅通工程 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 16075    Accepted Submission(s): 6677 Problem Description 省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可).经过调查评估,得到的统计表中列出

hdu 4771 Stealing Harry Potter&#39;s Precious (2013亚洲区杭州现场赛)(搜索 bfs + dfs) 带权值的路径

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4771 题目意思:'@'  表示的是起点,'#' 表示的是障碍物不能通过,'.'  表示的是路能通过的: 目的:让你从 '@' 点出发,然后每个点只能走一次,求出最小的距离: 解题思路:先用 bfs 求解出任意两点之间的距离,用 ans[i][j],表示点 i 到点  j 的距离: 然后用 dfs 递归求出从起点经过所有点的距离中,比较出最小的: AC代码: 1 #include<iostream>

HDU 1863:畅通project(带权值的并查集)

畅通project Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 16075    Accepted Submission(s): 6677 Problem Description 省政府"畅通project"的目标是使全省不论什么两个村庄间都能够实现公路交通(但不一定有直接的公路相连,仅仅要能间接通过公路可达就可以).经过

2017 计蒜之道 初赛 第三场 D. 腾讯狼人杀 (点边都带权的最大密度子图)

点边都带权的最大密度子图,且会有必须选的点. 写到一半没保存实验室断电,气炸.明天补详细题解. #include<bits/stdc++.h> using namespace std; const double eps = 1e-7; const int INF = 0x3f3f3f3f; const int MAXN= 405;//点数的最大值 const int MAXM= 1e6 + 10;//边数的最大值 #define captype double struct Edge{ int

带权值的并查集

博文:https://blog.csdn.net/yjr3426619/article/details/82315133 带全并查集 路径压缩,表达每个当前node与 当前node所在的并查集的root 之间的关系 并查集一定是单向连通的,所以一些node处理时 [node1,node2] weight 可能需要把 一端的闭区间变为开区间 俩个相对信息求出绝对信息   --水题 例题 : HDU 3038 //带权值并查集 #include<iostream> #include<cstd

Lightoj1009 Back to Underworld(带权并查集)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Back to Underworld Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description The Vampires and Lykans are fighting each other to death. The war has become so fierc