Tunnel Warfare Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7876   Accepted: 3259 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally sp…
Tunnel Warfare                                  Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast…
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对最少的个数. 前置技能 环序列 还 线段树的逆序对求法 逆序对:ai > aj 且 i < j ,换句话说数字大的反而排到前面(相对后面的小数字而言) 环序列:把第一个放到最后一个数后面,就是一次成环,一个含有n个元素序列有n个环序列. 线段树的逆序对求法:每个叶子节点保存的是当前值数字的个数.根…
http://acm.hdu.edu.cn/showproblem.php?pid=1540 题目大意:抗日战争期间进行地道战,存在n个村庄用地道连接,输入D表示破坏某个村庄(摧毁与其相连的地道, 包括其本身),输入R表示重建最后被破坏的那个村庄. 输入Q表示查询某村庄可通过地道到达多少个村庄(包含本身). 将题目理想化,即为找与某点直接或间接相连的有多少个点.即通过此点的线段的最大长度.当此点时破坏时默认为0.抽象为此过程后发现即为在线段上执行的操作,即线 段树知识点.分析:此点可能为孤立(0…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1540 题意:D代表破坏村庄,R代表修复最后被破坏的那个村庄,Q代表询问包括x在内的最大连续区间是多少. 其实这题直接二分查找也可以,但用线段树可以练一练手. 大致思路就是找查询点最近的左右两个0的位置(0表示被摧毁的),然后输出区间大小即可,如果这个点已经被摧毁那么就没有 连续的区间,那么输出0.线段树查询位置有点麻烦具体看代码. #include <iostream> #include <…
https://cn.vjudge.net/problem/HDU-1540 题意 D代表破坏村庄,R代表修复最后被破坏的那个村庄,Q代表询问包括x在内的最大连续区间是多少. 分析 线段树的区间内,我们要用三个变量记录左边连续区间,右边连续区间和最大连续区间. 其它看代码,要比较仔细. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include &l…
Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11180    Accepted Submission(s): 4389 Problem Description During the War of Resistance Against Japan, tunnel warfare was carried ou…
Description During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Except the two at the ends, every village was…
LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting from 0) Q A B: output the length of the longest consecutive increasing subsequence (LCIS) in [a, b].                  Input T in the first line, indic…
线段树功能:update:单点更新 query:区间最值 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 using namespace std; const int MAXN = 200008; int maxs[MAXN<<2]; void build(int l, int r, int rt) { if(l == r) { scanf(&quo…