POJ3468【线段树lazy操作】】的更多相关文章

上午理论AC,打到现在快吐了... 一个那么**Lazy操作打成这样,query操作和update操作都有问题,妈蛋,发现是mid<=s+1-真是蠢到家,明明是mid+1<=s卧槽连左和右都分不清... 什么是lazy? lazy做法: 查询一个区间,如果这个节点的区间正好是满足,那么直接返回,眼睛都不眨一下,如果不是,就要让根的标志和他的子节点搞一搞,然后继续分下去,判断与mid的关系,因为是从根节点下去,所以他肯定是满足区间的,只是怎么分的问题,有两个是区间变小,分别是查询区间完全在mid…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92921   Accepted: 28910 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…
又是一开始觉得的水题,结果GG了好久的东西... 题意是给你n个英雄,每个英雄开始为1级经验为0,最多可以升到k级并且经验一直叠加,每一级都有一个经验值上限,达到就升级.接着给你两种操作:W li ri ei:从第li到第ri个增加经验基数ei,注意这儿ei还需要乘以级数才是真正增加的经验,还有就是先在此等级下增加此等级倍数的经验,然后再判断升级情况 Q li ri :在第li到第ri个查找经验最多的值 记录最大值嘛,不过因为级数控制增加的倍数,也就是说区间更新时,多次更新标记得到的只是基数ei…
/* 本体在spoj375的基础上加了一些操作,用到线段树的lazy操作模板类型 */ #include<stdio.h> #include<string.h> #include<iostream> #include<map> #include<string.h> #include<stdlib.h> #include<math.h> using namespace std; #define N 11000 #define…
区间更新lazy操作一发. #include<cstdio> #include<iostream> #include<string.h> #include<algorithm> using namespace std; /* DOTA中屠夫的钩子有N个链子组成,每个链子可有金,银,铜,三种材质做成, 铜链价值1,银价值2,金价值3, 先对钩子进行Q次的更新操作, 求出更新完后钩子的价值. */ const int N=100007; struct st{ i…
E. DZY Loves Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output DZY loves colors, and he enjoys painting. On a colorful day, DZY gets a colorful ribbon, which consists of n units (they…
题目链接:https://nanti.jisuanke.com/t/40852 题意:给定一个01串s,进行m次操作,|s|<=1e6,m<=5e5 操作有两种 l r 0,区间[l,r]升序排序 l r 1,区间[l,r]降序排序 输出m次操作后的串s 官方解析: 维护区间1的个数,区间0的个数=区间长度-区间1的个数,完成区间赋值操作并更新即可. 个人思路: 线段树的操作都是log(n),如果带了lazy标记,就可以小于log(n),不必查询到每个点.例如将[1,3]都置为1,只用将t[2…
POJ 2777 Count Color --线段树Lazy的重要性 原题 链接:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59087 Accepted: 17651 Description Chosen Problem Solving and Program design as an optional course, you are…
JuQueen Time Limit: 5 Sec  Memory Limit: 512 MB Description Input Output Sample Input 10 10 5 state 0 groupchange 2 9 7 state 9 groupchange 0 2 10 change 0 -5 Sample Output 0 7 7 3 -3 线段树lazy的巧用 #include <iostream> #include <cstdio> #include &…
Memory Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5913    Accepted Submission(s): 1380 Problem Description Memory units are numbered from 1 up to N. A sequence of memory units is c…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 53749   Accepted: 16131 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…
题目链接:poj3468 题意:给定一段数组,有两种操作,一种是给某段区间加c,另一种是查询一段区间的和 思路:暴力的方法是每次都给这段区间的点加c,查询也遍历一遍区间,复杂度是n*n,肯定过不去,另一种思路是用线段树记录区间的和,每次查询的复杂度是lgn,修改不必更新到每个点,当某个区间全被修改时,我们可以给它加一个懒惰标记,表示这个区间的所有下面节点都需要更新,只是因为现在不需要使用而暂时没有更新.这样修改的复杂度也降到了lgn ac代码: #include <iostream> #inc…
我的线段树真的没救了......还是多练几道吧....... You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a…
http://acm.hdu.edu.cn/showproblem.php?pid=6315 题意 a数组初始全为0,b数组为1-n的一个排列.q次操作,一种操作add给a[l...r]加1,另一种操作query查询Σfloor(ai/bi)(i=l...r). 分析 真的是太naive啦,现场时没做出来. 看见区间自然想起线段树,那么这里的关键就是整除问题,只有达到一定数量才会对区间和产生影响. 反过来想,先把a[i]置为b[i],那么每次add时就是-1操作,当a[i]为0时区间和+1,再把…
http://poj.org/problem?id=2777 题目大意 涂颜色,输入长度,颜色总数,涂颜色次数,初始颜色都为1,然后当输入为C的时候将x到y涂为颜色z,输入为Q的时候输出x到y的颜色总数 很明显的区间线段树,然后加lazy思想记录 lazy操作为了避免查找到每一个子节点区间而费时,将查找到的区间作标记,但查找到这个区间或还要继续像下查找的时候 将此区间的数据传给下面两个区间树 因为这题颜色总类只有30种很少,所以偷了个懒,将判断与记录操作合并到一个结构体上了,然后用类似hash的…
You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbered 1 through N − 1. Each edge is associated with a weight. Then you are to execute a series of instructions on the tree. The instructions can be one…
1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成. 有长为N的数列,不妨设为a1,a2,-,aN .有如下三种操作形式: (1)把数列中的一段数全部乘一个值; (2)把数列中的一段数全部加一个值; (3)询问数列中的一段数的和,由于答案可能很大,你只需输出这个数模P的值. Input 第一行两个整数N和P(1≤P≤1000000…
题目传送门 题意:四种集合的操作,对应区间的01,问最后存在集合存在的区间. 分析:U T [l, r]填充1; I T [0, l), (r, N]填充0; D T [l, r]填充0; C T[0, l), (r, N]填充0并且[l, r]xor; S T [l, r]xor 线段树结点两个属性,cover[o]: 该区间是否填充(1, 0, -1),_xor[o]: 该区间是否异或反转(1, 0).最后(和[的区别可以原数*2判奇偶得 #include <cstdio> #includ…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 97196   Accepted: 30348 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…
题意:给你一些区间操作,让你输出最后得出的区间. 解法:区间操作的经典题,借鉴了网上的倍增算法,每次将区间乘以2,然后根据区间开闭情况做微调,这样可以有效处理开闭区间问题. 线段树维护两个值: cov 和 rev  ,一个是覆盖标记,0表示此区间被0覆盖,1表示被1覆盖,-1表示未被覆盖, rev为反转标记,rev = 1表示反转,0表示不翻转 所以集合操作可以化为如下区间操作: U l r:   把区间[l,r]覆盖成1I  l r:   把[0,l)(r,MAX]覆盖成0 D l r:  …
题目 : http://www.tsinsen.com/A1517 A1517. 动态树 时间限制:3.0s   内存限制:1.0GB    总提交次数:227   AC次数:67   平均分:49.52   将本题分享到:        查看未格式化的试题   提交   试题讨论 试题来源 中国国家队清华集训 2013-2014 第四天 问题描述 小明在楼下种了一棵动态树, 该树每天会在某些节点上长出一些果子. 这棵树的根节点为1, 它有n个节点, n-1条边. 别忘了这是一棵动态树, 每时每…
传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=1001 WZJ的数据结构(十) 难度级别:D: 运行时间限制:3000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 请你设计一个数据结构,高效执行以下过程: #include<iostream>using namespace std;const int maxn=100010;int A[maxn];int tp,ql,qr,v;int…
自己写了一个带结构体的WA了7.8次 但是测了几组小数据都对..感觉问题应该出在模运算那里.写完这波题解去对拍一下. 以后线段树绝不写struct!一般的struct都带上l,r 但是一条线段的长度确定的话,每一个节点的l,r都可以确定的,没必要用struct存上,如果不带上l,r那不是更没必要用结构体hhh 这道题有点坑的地方就是顺序问题 pushdown就是一个最大的难点 change表示改数字 add表示加上数字 multiply表示乘以一个数字 正确的方法应该是 先change 再mul…
题目 写了一天的线段树,这道题主要说明一下sum是赋值的,不是累加的,并且在push_down的时候lazy也是赋值的.因可能对懒标记的理解还不是很透彻吧. #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int Max = 1e5+10; typedef long long ll; struct Tree{ int L,R; ll sum; int…
Problem Description Chinese always have the railway tickets problem because of its' huge amount of passangers and stations. Now goverment need you to develop a new tickets query system.One train can just take k passangers. And each passanger can just…
Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others)Total Submission(s): 3830    Accepted Submission(s): 940 Problem Description Yuanfang is puzzled with the question below: There are n integers, a1, a2,…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 85502   Accepted: 26556 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…
线段树写得很少,这么基本的算法还是要会的…… #include<bits/stdc++.h> using namespace std; inline long long read() { , f = ; char ch = getchar(); ;ch = getchar(); } + ch - ';ch = getchar(); } return x*f; } ; int n,m,op,_l,_r,k; struct NODE{ int l,r; long long lazy,val; }n…
Time limit 1000 ms Memory limit 65536 kB Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finall…
链接:https://ac.nowcoder.com/acm/contest/925/K来源:牛客网 题目描述 公元2019年6月22日,白山茶王国与红玫瑰王国展开大战,在世外仙境——天空花园处,双方军团一字排开,在维持一字长蛇阵的队形下双方战士陷入混战. 然而,为了操控整个战局,白山茶公主与红玫瑰女巫都会一种AOE魔法,使得受到魔法波及的战士"叛变"(白山茶战士变为红玫瑰战士,红玫瑰战士变为白山茶战士). 可见,这场战争永远没有绝对的优劣势,局势瞬息万变.现在,白山茶公主邀请你协助她…