比较综合的一道题目. 二维的线段树,支持区间的add和set操作,然后询问子矩阵的sum,min,max 写完这道题也是醉醉哒,代码仓库里还有一份代码就是在query的过程中也pushdown向下传递标记. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; << ; int _sum, _min, _max, op, x1, x2, y1, y2, x…
题意: 给出一个具有N个点的树,现在给出两种操作: 1.get x,表示询问以x作为根的子树中,1的个数. 2.pow x,表示将以x作为根的子树全部翻转(0变1,1变0). 思路:dfs序加上一个线段树区间修改查询. AC代码: #include<iostream>#include<vector>#include<string.h>using namespace std;const int maxn=2e5+5;int sum[maxn<<2],lazy[…
Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.Now Pudge wants to do some operations on th…
Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include <queue> #include <cmath> #include <algorithm> #include <cstring> using namespace std; #define ll long long #define P pair<int,in…
题意  给出一段初始化全为1的区间  后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include<algorithm> #include<set> #include<vector> #include<cstring> #include<iostream> using namespace std; ; struct Node{ int l,r,su…
描述 A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be marked a value of endurance. For every attack of our secret weapon,…
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 finally decided to build an electoral wall for…
解题思路: 将矩阵每一行建立一棵线段树,进而变成一维问题求解.注意数组要开 4*N 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; ; int q, x1_, x2_, y1, y2, v_add, v_set; struct segment_tree { int sumv[4*maxn],…
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…
题目 给定一组数,要求进行若干次操作,这些操作可以分为两种类型: (1) CMD 1 beg end value 将数组中下标在[beg, end] 区间内数字都变为value (2) CMD 2 beg end 求出数组中下标在[beg ,end]区间中的所有数字的和 分析 树状数组在区间查询和单点修改情况下效率较线段树高一些,而无法像线段树一样在O(logN)的时间内完成区间修改.因此使用线段树解决.使用线段树主要的是定义好线段树节点的状态.(如代码中注释所说,状态一定要明确,且容易计算!)…