hdu4348】的更多相关文章

学可持久化treap的时候才发现自己竟然没写过需要标记下传的主席树,然而现在发现大部分操作都可以标记永久化,下传会增大占用空间. 这题一种写法是和普通的线段树一样标记下传,注意所有修改操作(包括put())都要新建点.于是MLE了. #include<cstdio> #include<algorithm> #define lson v[x].ls,L,mid #define rson v[x].rs,mid+1,R #define rep(i,l,r) for (int i=(l)…
Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Description Background To The Moon is a independent game released in November 2011, it is a role-playing adventure game powered by RPG Maker. The premise of To The Moon is ba…
#include<cstdio> #include<algorithm> #include<cstring> #define N 400000 using namespace std; ]; ],cnt,n,m,x,y,k,rson[],sum[]; bool cmp(node a,node b) { return a.x<b.x; } void update(int st,int ed,int x,int &y,int v) { //printf(&qu…
法一:暴力! 让干什么就干什么,那么久需要可持久化线段树了. 但是空间好紧.怎么破? 不down标记好了! 每个点维护sum和add两个信息,sum是这段真实的和,add是这段整体加了多少,如果这段区间被完全包含,返回sum,否则加上add * 询问落在这段区间的长度再递归回答. 怎么还是MLE? 麻辣鸡指针好像8字节,所以改成数组的就过了... #include<cstdio> #include<cstring> #include<cstdlib> #include&…
Problem Description BackgroundTo The Moon is a independent game released in November 2011, it is a role-playing adventure game powered by RPG Maker.The premise of To The Moon is based around a technology that allows us to permanently reconstruct the…
和线段树类似,每个结点也要打lazy标记 但是lazy标记和线段树不一样 具体区别在于可持久化后lazy-tag不用往下传递,而是固定在这个区间并不断累加,变成了这个区间固有的性质(有点像分块的标记了) update就按照这么来 int update(int last,int L,int R,int c,int l,int r){ int now=++size; T[now]=T[last]; if(L<=l && R>=r){ T[now].sum+=(r-l+)*c; T[…
题解: 因为卡空间,所以直接到spoj上面去做了 区间修改的线段树 但是加lazy会把之前的操作修改 正确的解法是lazy不下传,只是在当前计算 但是听说可以记录时间的下传,我弱弱不会 代码: #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; ; typedef long long ll; struct aa { int lc…
http://acm.hdu.edu.cn/showproblem.php?pid=4348 sb的标记永久化即可,刚开始add和sum没复制过来wa了两发...,操作和原来的都一样,出来单点变成区间,还要加一个标记永久化,这样就不用pushdown新加节点而爆内存了 #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi ac…
浅谈主席树:https://www.cnblogs.com/AKMer/p/9956734.html 浅谈标记永久化:https://www.cnblogs.com/AKMer/p/10137227.html 题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4348 相比一般的主席树,这个要多支持一个操作,那就是区间修改.我们不能把区间里的每一条链都建出来,因为那样时间空间都不允许,所以我们可以依靠标记永久化来实现.每次询问的时候,把一路上的标记全…
传送门 对于这个题,显然要打lazy标记了,但是lazy标记pushdown的时候肯定会增加一大堆节点,然后就MLE了.(题解这么说的,我其实不会pushdown) 所以,就换另一种方式,把标记直接打到当前区间,把当前区间的父亲节点大小都更新.求区间和的时候把沿途的标记都加起来就可以了. 注意分多钟情况. ——代码 #include <cstdio> #define ls son[now][0], l, mid #define rs son[now][1], mid + 1, r #defin…