题目描述 区间修改有别于单点修改,如果每次都修改到叶子节点,复杂度可以退化到O(n)。 因此为节点引入一个lazy标记,修改时,如果待修改区间与某个节点的区间重合,那么这个节点更新值后标记lazy,不再修改其子节点。 类似于查询操作,这个修改操作的复杂度是O(logn)。 另外,查询或修改时,如果遇...
分类:
其他好文 时间:
2015-05-14 20:00:21
阅读次数:
122
Can you answer these queries?Problem DescriptionA lot of battleships of evil are arranged in a line before the battle. Our commander decid...
分类:
其他好文 时间:
2015-05-05 16:05:10
阅读次数:
100
分析:线段树的应用,区间修改,使用延迟标记进行延迟修改。
#include
using namespace std;
#define N 100010
class SegmentTree
{
private:
struct Node
{
int left,right; //左右子节点
int sum; //区间和
int lazy; ...
分类:
其他好文 时间:
2015-05-03 16:06:09
阅读次数:
126
#include
#include
#define maxn 100000 + 10
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
struct Node
{
int sum, lazy;
} T[maxn<<2];
void PushUp(int rt)
{
T[rt].sum = T[rt<<1]....
分类:
其他好文 时间:
2015-05-03 12:03:50
阅读次数:
157
Just a Hook
Time Limit: 2000MS
Memory Limit: 32768KB
64bit IO Format: %I64d & %I64u
Submit Status
Description
In the game of DotA, Pudge’s meat hook is actually the m...
分类:
其他好文 时间:
2015-05-03 12:03:35
阅读次数:
172
A Simple Problem with Integers
Time Limit: 5000MS
Memory Limit: 131072KB
64bit IO Format: %I64d & %I64u
Submit Status
Description
You have N integers, A1, A2, ... ,...
分类:
其他好文 时间:
2015-05-03 10:42:52
阅读次数:
192
经典的线段树题目,也可以用块链来做。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 typedef __int64 ll; 8 const ll M = 400; 9 ll b...
分类:
其他好文 时间:
2015-05-02 11:09:58
阅读次数:
137
整体二分。首先,第k大问题是满足二分性的(只要我们能够快速求出集合中比某个数小的数的个数,那么就可以快速找出该集合的第K大)。然后考虑整体二分,关键是我们怎么将询问分到其对应的答案子区间中。和普通的区间第K大的做法一样,我们先将修改按照大小排序(普通的区间第K大就是给出的原序列,而这里就是区间修改)...
分类:
其他好文 时间:
2015-04-28 22:45:38
阅读次数:
243
1 struct node { 2 int l, r; 3 int lazy; 4 LL sum; 5 LL add; 6 }tree[MAXN]; 7 int a[100005]; 8 void build(int v, int l, int r) { 9 ...
分类:
其他好文 时间:
2015-04-10 23:47:58
阅读次数:
184
模板题:
#include
#include
#define ll long long
const int N = 100000 + 10;
ll sum[N << 2];
ll addv[N << 2];
int num[N];
int n,q;
void pushUp(int u) {
sum[u] = sum[u * 2] + sum[u * 2 + 1];
}
void b...
分类:
其他好文 时间:
2015-04-09 22:01:54
阅读次数:
140