2018网络预选赛 徐州G 线段树】的更多相关文章

线段树,假设求(x1,y1)点的贡献,就找所有比该点出现时间晚,且x坐标大于x1的点中y最大的,贡献就是Y-y1,由于题目条件限制,不可能有x坐标大于(x1,y1)且y坐标大于y1的点,所以贡献肯定为正. 思路参考了这篇博客:https://blog.csdn.net/qq_39599067/article/details/82560005#accode. #include<bits/stdc++.h> using namespace std; ; struct node{ int x,y;…
设读入的数组是a,树状数组用来维护a数组区间和sum,线段树用来维护一个另一个数组ssum的区间和,区间每个点a[i]*(n-i+1),那么l-r的答案是l-r的ssum-(n-r)*(sum[r]-sum[l-1]) (纸上画一下就知道了) #include<bits/stdc++.h> using namespace std; const int maxn=100010; int n,q,ql,qr,p; long long v,_sum; long long sum[maxn],ssum…
There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy ) means the wave is a rectangle whose vertexes are ( 00 , 00 ), ( xx , 00 ), ( 00 , yy ), ( xx , yy ). Every time the wave will wash out the trace of…
Problem Description Given a binary string S[1,...,N] (i.e. a sequence of 0's and 1's), and Q queries on the string.There are two types of queries:1. Flipping the bits (i.e., changing all 1 to 0 and 0 to 1) between l and r (inclusive).2. Counting the…
传送门 给出一个数字字串,给出若干个询问,询问在字串的一段区间保证出现2017" role="presentation" style="position: relative;">20172017而不出现2016" role="presentation" style="position: relative;">20162016需要删去的最少字符. 下面定义5个状态. 状态0:连2都没有 状态1:只…
题目中没有明说会爆int和longlong 的精度,但是在RNG函数中不用unsigned int 会报精度,导致队友debug了很久... 根据每次生成的l,r,v对区间更新m次,然后求 i*ai的异或和.挺裸的线段树,只要ai<v就更新ai.在线段树结点中维护区间最小值,每次更新时,如果区间最小值>=v,那么就不用更新了. #include<bits/stdc++.h> #define lson rt << 1 #define rson rt << 1…
#include<bits/stdc++.h>using namespace std;int st[1000007];int top;int s[1000007],t[1000007];int mx[4000007];int sum[4000007];int head[1000007],to[2000007],nex[2000007];int n,k;int a[10000077];int dfn;int tot;void pushup(int rt){    mx[rt]=max(mx[rt…
原题地址 Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Others)Total Submission(s): 887    Accepted Submission(s): 336 Problem Description In a galaxy far, far away, there are two integer sequence a and b o…
突然想到的节约时间的方法,感觉6翻了  给你n个数字,接着m个询问.每次问你一段区间内不大于某个数字(不一定是给你的数字)的个数 直接线段树没法做,因为每次给你的数字不一样,父节点无法统计.但是离线一下,如果后面的询问可以用前面已经处理过的一些东西,则可以节约时间.换句话说,就是直接把给数字z进行从小到大排序,每次暴力更新数字a小于等于数字z的叶子节点,数字a赋值为极大值,这样前面更新了的数字a在后面就不需要再更新了,而且后面的数字z一定不小于前面更新了的数字a,而且总数一共最多更新n次  做了…
array 题目传送门 解题思路 操作1是把第pos个位置上的数加上\(10^7\),操作2是找到区间[1,r]中没有且大于k的最小的数.注意到k的范围是小于等于n的,且n的范围是\(10^5\),远小于\(10^7\),所以对于操作1,可以视为把第pos个位置上的数删去. 因为所有节点上的数都是唯一的,所以建立一颗权值线段树,存入每个权值对应的位置,维护其最大值和最小值.为了保证一定有答案,建立的权值范围是[1,n+1].对于操作1,直接把pos对应的权值的叶子节点修改为0,代表这个数不存在即…
---恢复内容开始--- 传送门 参考资料: [1]:https://blog.csdn.net/mmk27_word/article/details/89788448 题目描述: The Fool comes to a cross-road, filled with energy, confidence and purpose, knowing exactly where he wants to go and what he wants to do. But he comes to a dea…
还带这么做的,卧槽,15分钟就被A了的题,居然没搞出来 若某位是1,则前两个为wb,这位就是w #include<cstdio> #include<cstring> #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; ; ]; char str[maxn]; int num[maxn]; void pushup(int rt) { sum[rt]=sum[rt<&…
不能直接使用成段增减的那种,因为一段和的平方根不等于平方根的和,直接记录是否为1,是1就不需要更新了 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> using namespace std; #define MOD 100000000…
就是不知道时间该怎么处理,想了好久,看了别人的题解发现原来是暴力,暴力也很巧妙啊,想不出来的那种  -_-! #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> using namespace std; #define MOD 10000…
题目链接:https://pintia.cn/problem-sets/1036903825309761536/problems/1041156323504345088 题意:小明从某一点出发,向右方前进,只有路口是绿灯(用1代表)的时候才可通行,红灯要等待,所有红绿灯每过一秒变化一次(红->绿,绿->红),问从任意一点到该点右边的任意一点的所花费的时间和. 题解:设t(1,n)是从点1到点n所花费的时间,我们可以经过特殊的判断t(1,n)拆分成t(1,a)+t(a,n)+c (c是1,-1,…
题面 传送门:https://www.luogu.org/problemnew/show/P2824 Solution 这题极其巧妙. 首先,如果直接做m次排序,显然会T得起飞. 注意一点:我们只需要找到一个数. 所以说,我们可以考虑一个绝妙的想法:我们可以用二分答案的方法缩小要找的数的区间. 考虑二分一个值,判定p位置的数排序之后,p位置上的数是否>=mid 如果>=mid,则向右找,否则向左找. 怎么判定p位置的数排序之后是否>=mid呢? 考虑这样做:扫描一遍原数组,>=mi…
https://nanti.jisuanke.com/t/31459 思路 凡是后面的轨迹对前面的轨迹有影响的,可以尝试从后往前扫 区间修改需要push_down,单点更新所以不需要push_up(用于区间查询) 多颗线段树的时候将函数写进结构体里,这样所有函数只需要写一次了 #include<bits/stdc++.h> #define pb push_back #define M 100005 using namespace std; int n,i,x[M],y[M],sz,tp; lo…
Problem:Portal传送门 Problem:Portal传送门  原题目描述在最下面.  我理解的题意大概是:有n次涨潮和退潮,每次的范围是个x×y的矩形,求n次涨退潮后,潮水痕迹的长度.  不存在此i,j∈[1,n],i≠j,xi≤xj且yi≤y Solution:  每次潮水可能会冲刷掉之前的潮水的一部分痕迹,但是它又不会完全冲刷.  考虑从最后一次潮水开始往前算贡献,分x,y方向计算.  假设此次潮水的范围是[xi,yi],找出大于等于xi的最大Y,则y方向的新增痕迹长度为yi−Y…
H.Ryuji doesn't want to study 27.34% 1000ms 262144K   Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That…
题目链接:https://nanti.jisuanke.com/t/30996 中文题目: 在喝茶的过程中,公主,除其他外,问为什么这样一个善良可爱的龙在城堡里被监禁Lpl?龙神秘地笑了笑,回答说这是个大秘密.暂停后,龙补充道: - 我们有合同.租赁协议.他总是一整天都在工作.他喜欢沉默.除此之外,住在城堡还有更多的优势.比如说,很容易证明未接来电的合理性:电话铃声无法从手机离开的城堡的另一侧到达.因此,监禁只是一个故事.实际上,他思考一切.他很聪明.例如,他开始用整个城堡中的节能灯替换白炽灯.…
https://nanti.jisuanke.com/t/30996 题意 每天增加m个灯泡,n个房间,能一次性换就换,模拟换灯泡过程.询问第几天的状态 分析 离线做,按题意模拟.比赛时线段树写挫了..导致不断超时,我太弱了.每次询问符合要求的最左边的点. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #i…
During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Lpl in the Castle? Dragon smiled enigmatically and answered that it is a big secret. After a pause, Dragon added: — We have a contract.…
题目链接:https://nanti.jisuanke.com/t/31459 样例输入 3 1 4 4 1 3 3 样例输出 10 题意: 二维平面上给出 $n$ 个点,每个点坐标 $\left( {x,y} \right)$ 代表一个从原点到 $\left( {x,y} \right)$ 的长方形, 其中标记红线为线段 $\left( {x,0} \right)\left( {x,y} \right)$ 和 $\left( {0,y} \right)\left( {x,y} \right)$…
题意 给出一个有根树(根是1),有n个结点.初始的时候每个结点的值都是0.下面有q个操作,操作有两种,操作1.将深度为L的点的值全部增加X.操作2.查询以x为根的子树的结点值得和. 其中N,Q<=1e5 分析 一看这种没有办法直接用数据结构解决得问题就要考虑分块.这个题其实也不算是分块,应该是用了分块的思想进行分类而已.场上也一直在想分块但是可能是自己太菜了,赛后看了题解补的. 分块最重要的就是算时间复杂度啊.我们按照每一层的结点数进行分类.节点数>block的为第一类,节点数<=为第二…
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That means, if he reads books from ll to rr, he will get a…
题目4 : 80 Days 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 80 Days is an interesting game based on Jules Verne's science fiction "Around the World in Eighty Days". In this game, you have to manage the limited money and time. Now we simplified the game…
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That means, if he reads books from ll to rr, he will get a…
题目链接:https://nanti.jisuanke.com/t/31714 题意:给你一棵树,初始全为0,有四种操作: 1.u-v乘x    2.u-v加x   3. u-v取反  4.询问u-v的和 思路: 除去第三个操作就是很简单的树链剖分+线段树多重标记下放,所以我们只要考虑怎么维护第三个操作就好了, 由题目给的取反可知:!x =  (2^64-1) - x;   但是这样维护还是很麻烦,因为这道题是对2^64取模的,我们可以 尝试把这个式子转换成只有加法和乘法的,这样就可以将其和前面…
题目链接: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://codeforces.com/gym/101991/problem/G 题意:给出 n 个数,q 次询问区间[ li,ri ]之间有多少个 GCD = di 的连续子区间. 题解:类似HDU 5726,可以先看一下这个blog:https://blog.csdn.net/u013569304/article/details/51987053 考虑离线,先预处理出[ 1,n ]之间所有的GCD,同时需要记录每种 GCD 的区间,方法是固定一个右端点R,对于区间[ L,R…