hdu 4288 Coder】的更多相关文章

Coder 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4288 题意:有三种类型的操作,(1)."add x",表示往集合里加入�数x.(2)."del x"表示将集合中数x删除.(3)."sum"求出从小到大排列的集合中下标模5为3的数的和.集合中的数都是唯一的. 思路:这题巧妙的地方在于先离线输入,然后离散化.输入的数字依照从小到大排序,然后作为线段树的叶子结点.每一个结点包括两个部分,一是该结…
线段树好题,和 15 年的广东省省赛 C 题有相似之处,一开始我的思路有偏差,看了别人的博客后感觉处处技巧都是精华,主要是区间合并的技巧一时很难想到,先附上代码: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define root int rt, int l, int r #define lson rt << 1, l, mid #define rs…
题意略. 离线处理,离散化.然后就是简单的线段树了.需要根据mod 5的值来维护.具体看代码了. /* 线段树+离散化+离线处理 */ #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef long long ll; #define N 100010 ll sum[N<<2][5]; int a…
题意: 给定三种操作 1. add x 向序列中添加x,添加之后序列还保持有序 2. del x  删除序列中值为x的元素 3. sum  求下边模5等于3的元素和 思路: 直接暴力也可以过,就是看暴力写的好不好了.用数组直接暴力可过. 暴力代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; typedef long long ll; int a[max…
这题跟ZOJ 3606的解题思路很相似. 题意:有3中操作:1.向集合中增加一个数x(1≤x≤1e9):2.从集合中删去一个数x(保证这个数存在):3.查询集合中所有位置满足i%5==3的数a[i]的和,集合中的数按升序排列.给你一共N个操作,输出每次查询的和. 做法:因为操作只有10^5个,所以将所有查询中的数保存下来,排序之后离散化.每个数对应一个“位置”,通过标记这个“位置”是否已用来表示该数是否在集合中. 线段树节点记录两个信息: cnt:这一段“位置”中含有多少个数,pushUp的时候…
题意: 三种操作: 1. add x – add the element x to the set;2. del x – remove the element x from the set;3. sum – find the digest sum of the set. The digest sum should be understood by:sum(ai) where i % 5 ==3 where the set S is written as {a1, a2, ... , ak} sa…
题意: 刚开始有一个空集合.有三种操作: 1.往集合中加入一个集合中不存在的数 x 2.从集合中删除一个已经存在的数 x 3.计算集合的digest sum并输出.       digest sum求法:将集合中所有数从小到大排序,得到a1<a2<...<an. digest sum = sum(ai) where i mod 5 = 3 数据范围: N ( 1 <= N <= 105 ) 1 <= x <= 109. For any "add x&qu…
Coder Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4838    Accepted Submission(s): 1853 Problem Description In mathematics and computer science, an algorithm describes a set of procedures…
题目传送门 #include <cstdio> #include <cstring> #define lson l, m, rt << 1 #define rson m + 1, r, rt << 1 | 1 + ; ]; void pushup(int rt) { % == ) sum[rt] += sum[rt >> ]; | % == ) sum[rt] += sum[rt >> | ]; } void build(int l,…
http://acm.hdu.edu.cn/showproblem.php?pid=4288 開始的时候,果断TLE,做的方法是,线段树上只维护%5==3的坐标,比方1 2 3 4 5 6 7  假设删除第三个数,就将3,6的位置全+1,就是向右偏移以为,可是求和还是非常慢,所以即使10秒,还是TLE... 正确做法: 1.节点内维护sum[0...4]分别代表区间内%5==i的和 2.结点维护点的个数,cnt 3.离散化处理,然后每次插入时,经过的结点cnt+1或-1,叶子节点Sum[0]就是…
题意: 维护一个有序数列{An},有三种操作: 1.添加一个元素. 2.删除一个元素. 3.求数列中下标%5 = 3的值的和. 解题思路: 看的各种题解,今天终于弄懂了. 由于线段树中不支持添加.删除操作,所以题解写的是用离线做法. 我们来看它是如何解决添加.删除的问题的. 首先将所有出现过的数记录下来,然后排序去重,最后根据去重结果建树,然后每个操作数都会对应线段树中的一个点. 遇到添加.删除操作的时候,只要把那个节点的值改变,然后将它对下标的影响处理好就可以. 那么如何处理这些操作对下标的影…
题目传送门 题意:集合,add x, del x, 求和 分析:首先,暴力可以过这题.用上线段树能大大降低时间的消耗,具体就是类似开了5棵线段树,每个节点都有5个空间,表示该区间的id%5后的和,区间合并右边的id‘ = i + leftnum,子节点要存到sum[o][1]表示%5=1.还需要对数据离线离散化. //#include <bits/stdc++.h> #include <cstdio> #include <algorithm> #include <…
题意: n个操作 在[1, 100000]  的区间上add 或del数( 必不会重复添加或删除不存在的数) sum 求出整个集合中 (下标%5 == 3 位置) 的数   的和 注意数据类型要64位 #include <stdio.h> #include <string.h> #include <queue> #include <set> #include <functional> #include <map> #define N…
原文地址:http://blog.csdn.net/zearot/article/details/48299459(如有侵权,请联系博主,立即删除.) 线段树详解    By 岩之痕 目录: 一:综述     二:原理    三:递归实现    四:非递归原理      五:非递归实现 六:线段树解题模型    七:扫描线   八:可持久化 (主席树)     九:练习题 一:综述 假设有编号从1到n的n个点,每个点都存了一些信息,用[L,R]表示下标从L到R的这些点. 线段树的用处就是,对编号…
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15898    Accepted Submission(s): 5171 Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem.…
有一组数据是在客人到达和出发时间,问:多少把椅子的能力,以满足所有客人的需求,可以有一个地方坐下要求. 有些人甚至开始考虑暴力法,这些数据是少,其实这个问题很多数据, 暴力需求O(n*n)的时间效率,显然,将加班,因此,有必要O(n) 或O(nlgn)算法. 属于一道想透了就很easy的,可是没想过就会很困难的题目. 解法是: 把全部客人到来和离开的时间都排成序列.每次客人到来须要n张桌椅,那么就+上n,每次客人离开就会返还n张桌椅,那么就-去n,求这种最大值. 详细算法代码就那么几行,处理IO…
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional contest, all the ACMers are walking alone a very long avenue to the dining hall in groups. Groups can vary in size for kinds of reasons, which means, sev…
http://acm.hdu.edu.cn/showproblem.php?pid=1087 Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.QHand In HandOnline Acmers Forum |DiscussStatistical Charts Problem ArchiveRealtime Judge StatusAuthors Ranklist       C/C…
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能超过背包的容量1-P. 在这个条件下,让装入背包的物品的总价值,也就是bag[i].[v]的和最大 bag.v是每一件物品的价值,bag.p是每件物品的体积 像上面这样想是行不通的.下面有解释 这道题麻烦的是概率这东西没法用个循环表示出来,根据我以往的经验,指望着把给出的测试数据乘上一百或者一万这种…
http://acm.hdu.edu.cn/showproblem.php?pid=1548 Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.QHand In HandOnline Acmers Forum |DiscussStatistical Charts Problem ArchiveRealtime Judge StatusAuthors Ranklist       C/C…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943…
http://acm.hdu.edu.cn/showproblem.php?pid=2126 Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1904    Accepted Submission(s): 711 Problem Description When the winter holiday…
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5651 bc:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=682&pid=1002 xiaoxin juju needs help  Accepts: 150  Submissions: 966  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 6…
xiaoxin juju needs help 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5651 Description As we all known, xiaoxin is a brilliant coder. He knew palindromic strings when he was only a six grade student at elementry school. This summer he was working a…
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116…
Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description When the winter holiday comes, a lot of people will have a trip. Generally, there are a lot of souvenirs to sell, and sometimes…
Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1886    Accepted Submission(s): 699 Problem Description When the winter holiday comes, a lot of people will have a trip. Genera…
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1614    Accepted Submission(s): 566 Problem Description Mr Potato is a coder.Mr Potato is the BestCoder. One night, an amazing…
Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1662    Accepted Submission(s): 611 Problem Description When the winter holiday comes, a lot of people will have a trip. Genera…
面向组合子 面向组合子(Combanitor-Oriented),是最近帮我打开新世界大门的一种pattern.缘起haskell,又见monad与ParseC,终于ajoo前辈的几篇文章. 自去年9月起正式回归C#以来,我又逐渐接受了不少新的paradigm(虽然主要原因还是在学校用C#的方法太山寨),其中对我影响比较深刻的就是codegen.此codegen非compiler中的codegen,可能更像是meta-programming中的codegen.抽象来说,就是作为一个嵌入于构建流程…