SCUT - 321 - Tobby's magic - 线段树】的更多相关文章

https://scut.online/p/321 第一次做区间线段树. 感觉和单点的一样啊.pushdown的时候要注意一些问题,st的值有可能是跟区间长度有关的. #include<bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { int x=0; int f=0; char c; do { c=getchar(); if(c=='-') f=1; } while(c<'0'||…
F. Heroes of Making Magic III time limit per test:3 seconds memory limit per test:256 megabytes input:standard input output:standard output I’m strolling on sunshine, yeah-ah! And doesn’t it feel good! Well, it certainly feels good for our Heroes of…
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2489    Accepted Submission(s): 759 Problem Description When the magic ball game turns up, Kimi immediately falls in it. The int…
https://scut.online/p/337 这个东西是个阶梯状的.那么可以考虑存两棵树,一棵树是阶梯的,另一棵树的平的,随便一减就是需要的阶梯. 优化之后貌似速度比树状数组还惊人. #include<bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { int x=0; int f=0; char c; do { c=getchar(); if(c=='-') f=1; } while…
https://scut.online/p/77 线段树的一种奇怪的应用,暴力区间更新,每次update直接pushdown到底部,然后从维护底部.这样下次update的时候假如提前遇到底部就很快返回了.每个节点更新60次,单次更新nlogn.更新完毕之后每次update都是几乎一个log就返回了. #include<bits/stdc++.h> typedef long long ll; using namespace std; const int MAXM = 100000; ll a[M…
https://scut.online/p/153 其实不需要用线段树,只关心相邻元素的差,像神仙那样用差分就可以O1维护的. 但是我偏要用. 交之前写的那个,注意没有st本身的线段树只有lazy标记,每次必须先query才能得到真正的a数组,反正也就一点点常数干脆都query算了. 一开始少考虑一种特殊情况,l==r的时候,这个时候要是l本身是山峰就重复了. 第二次我居然用新的a[l]和旧的a[l+1]进行比较? 第三次就全部用新值进行比较了,也可以. 其实把第二次的那个bug修复也可以通过.…
magic balls Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 323    Accepted Submission(s): 90 Problem Description The town of W has N people. Each person takes two magic balls A and B every day.…
E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/problem/E Description One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering b…
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出一棵二叉树,每个结点孩子数目为0或者2.每个节点都有一个权值,初始在根,扔一个筛子,筛子的值与结点的权值大小关系影响往左往右的概率. 问给出筛子权值,问到达某个结点的概率. http://acm.hdu.edu.cn/showproblem.php?pid=4605 做法:肯定需要统计每个点到根的路径中,有哪些结点是需要往左孩子走,哪些需…
同一道题  http://blog.csdn.net/zy691357966/article/details/44680121 区间查询最大值 用线段树 比单调队列慢 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <ctime> #include <algorithm> #include <iostream>…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题解: 方法一:贪心. 在草稿纸上试多几次可以知道,删除数字中从左到右最后一位递增(可以等于)的数字,可以得到最小值,在这个基础下,又继续删除最后一位递增的数字,得到的依然是最小值.这就表明当前这步的贪心不仅是当前最优,而且对于下一步贪心来说也是最优的.所以每次删除最后递增项就可以了. 初期代码(每次循环找最后递增项): Accepted 3183 46MS 1408K 1259 B G++…
题目链接:http://codeforces.com/contest/981/problem/G 题目大意: 有n个初始为空的‘魔法’可重集,向一个‘可重集’加入元素时,若该元素未出现过,则将其加入:否则该可重集中所有元素的个数都会翻倍. 例如将$2$加入${1,3}$会得到${1,2,3}$,将$2$加入${1,2,3,3}$会得到${1,1,2,2,3,3,3,3}$. $q$次操作,每次操作要么向一个区间内的所有可重集加入某个元素,要么询问一个区间内可重集的大小之和. $n,q ≤ 2×1…
正题 题目链接:https://www.luogu.com.cn/problem/P6847 题目大意 \(n\)个点的一棵树上,每个时刻可以割掉一些边,一些节点上有果实表示如果在\(d_i\)时刻这个点恰好不与\(1\)联通,那么就可以获得\(w_i\)的价值. \(1\leq n,k\leq 10^5\) 解题思路 设\(f_{x,i}\)表示节点\(x\)在时刻\(i\)之前割掉时的最大权值那么相当与在儿子里面选一个最大的\(f_{y,j}(j\leq i)\)合并上来. 这是一个很经典的…
前言 已经是第三次遇到原题. 第一次是在 J O I 2021 S p r i n g C a m p \rm JOI2021~Spring~Camp JOI2021 Spring Camp 里遇到的类似的题(Food Court),我当初就用的启发式合并平衡树做法,但是由于常数不够优,没能通过 2 e 5 \tt2e5 2e5 的测试点.当时就只能用线段树合并做, O ( n log ⁡ n ) \rm O(n\log n) O(nlogn) ,但是我不会. 第二次是在打 C E O I 20…
Necklace Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2083    Accepted Submission(s): 747 Problem Description Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ba…
Problem 1050: Just Go Time Limits:  3000 MS   Memory Limits:  65536 KB 64-bit interger IO format:  %lld   Java class name:  Main Description There is a river, which contains n stones from left to right. These stones are magic, each one has a magic nu…
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnlySuccess的博文“完全版线段树”里的大部分题目,其博文地址Here,然后也加入了自己做过的一些题目.整理时,更新了之前的代码风格,不过旧的代码仍然保留着. 同样分成四类,不好归到前四类的都分到了其他.树状数组能做,线段树都能做(如果是内存限制例外),所以也有些树状数组的题目,会标示出来,并且放…
题目链接:BZOJ - 3995 题目分析 这道题..是我悲伤的回忆.. 线段树维护连通性,与 BZOJ-1018 类似,然而我省选之前并没有做过  1018,即使它在 ProblemSet 的第一页. 更悲伤的是,这道题有 40 分的暴力分,写个 Kruskal 就可以得到,然而我写了个更快的 DP . 这本来没有什么问题,然而我的 DP 转移少些了一种情况,于是...爆零.没错,省选前20名可能就我没有得到这 40 分? 不想再多说什么了...希望以后不要再这样 SB 了,如果以后还有机会的…
Let the light guide us Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 62768/32768 K (Java/Others) Total Submission(s): 677    Accepted Submission(s): 226 Problem Description Plain of despair was once an ancient battlefield where those brave…
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an innate talent, gaining it through study and practice, or receiving it from another being, often a god, spirit, or demon of some sort. Some wizards ar…
题目链接:https://nanti.jisuanke.com/t/38228 Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values in the interval, multiplied by the smallest value in the interval. Now she is planning to find the max value…
Magician Problem Description Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an innate talent, gaining it through study and practice, or receiving it from another being, often a god, spirit, or demon…
每个线段树维护一个行向量[A,B,C,len]分别是这个区间的A,B,C区间和与区间长度,转移显然. 以及此题卡常,稍微哪里写丑了就能100->45. #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define ls (x<<1) #define rs (ls|1) #define lson ls,L,mid #define rson r…
线段树+单调栈+前缀和--2019icpc南昌网络赛I Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values in the interval, multiplied by the smallest value in the interval. Now she is planning to find the max value of the inter…
Fence Obstacle Course Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 2524   Accepted: 910 Description Farmer John has constructed an obstacle course for the cows' enjoyment. The course consists of a sequence of N fences (1 <= N <= 50,0…
Description There is a river, which contains n stones from left to right. These stones are magic, each one has a magic number Ai which means if you stand on the ith stone, you can jump to (i +1)th stone, (i+2)th stone, ..., (i+Ai)th stone(when i+Ai >…
Magician Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1613    Accepted Submission(s): 470 Problem Description Fantasy magicians usually gain their ability through one of three usual methods:…
Description Plain of despair was once an ancient battlefield where those brave spirits had rested in peace for thousands of years. Actually no one dare step into this sacred land until the rumor that “there is a huge gold mine underneath the plain” s…
矩阵乘法来进行所有路径的运算, 线段树来查询修改. 关键还是矩阵乘法的结合律. Harry And Math Teacher Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 326    Accepted Submission(s): 89 Problem Description As we all know, Harry Porter…
One day Natalia was walking in the woods when she met a little mushroom gnome. The gnome told her the following story: Everybody knows that the mushroom gnomes' power lies in the magic mushrooms that grow in the native woods of the gnomes. There are …