Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来值开根号下的值.有两种操作,第一种就是上面描述的那种,第二种就是询问某个区间内的船的战斗值的总和. 解题思路 使用线段树就不用多说了,关键是如果不优化的话会超时,因为每次修改都是需要递归到叶子节点,很麻烦,但是我们发现,如果一个叶子节点的值已经是1的话,那个再开方它也是1,不变,这样我们就只需要判断…
V - Can you answer these queries? HDU - 4027 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开十几次就变成1了,所以就直接单点更新,但是这个可以剪枝. 如果碰到区间长度和区间大小相同就可以不用更新了. 我也是无语了,想到刚刚的做法之后很好写了, 不过要注意以下x,y 大小可能x>y, 这个bug如果不是之前看题解的时候瞄到了,我可能找不出来了. 因为我写对拍我肯定会保证x<y 的,还是就是…
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, it…
1557. Can you answer these queries II Problem code: GSS2 Being a completist and a simplist, kid Yang Zhe cannot solve but get Wrong Answer from most of the OI problems. And he refuse to write two program of same kind at all. So he always failes in co…
Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间合并(单点更新.区间查询) 代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; ; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1…
GSS2 - Can you answer these queries II #tree Being a completist and a simplist, kid Yang Zhe cannot solve but get Wrong Answer from most of the OI problems. And he refuse to write two program of same kind at all. So he always failes in contests. When…
Can you answer these queries III(luogu) Description 维护一个长度为n的序列A,进行q次询问或操作 0 x y:把Ax改为y 1 x y:询问区间[l,r]的最大子段和 数据范围:n,q<=5e4,-1e4<=Ai<=1e4; Solution 线段树处理区间最大子段和 res为区间最大子串和 sum为区间和 prel和prer分别为从区间左端点和右端点开始的最大子串和 Code #include <cstdio> #incl…
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, it…
传送门 线段树经典题. 就是让你求左端点在[l1,r1][l1,r1][l1,r1]之间,右端点在[l2,r2][l2,r2][l2,r2]之间且满足l1≤l2,r1≤r2l1\le l2,r1 \le r2l1≤l2,r1≤r2的最大子段和. 直接分类讨论就行了. 如果两个区间不相交的话,答案就是rmax(l1,l2)+sum(l2+1,l2−1)+lmax(l2,r2)rmax(l1,l2)+sum(l2+1,l2-1)+lmax(l2,r2)rmax(l1,l2)+sum(l2+1,l2−…
前言 线段树菜鸡报告,stO ZCDHJ Orz,GSS基本上都切完了. Solution 考虑一下用线段树维护一段区间左边连续的Max,右边的连续Max,中间的连续Max还有总和,发现这些东西可以相互合并,然后直接写就好了. #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<algorithm> #include<queue&…