题意 题目链接 Sol 这题关键是注意到题目中的\(b\)是个排列 那么最终的答案最多是\(nlogn\)(调和级数) 设\(d_i\)表示\(i\)号节点还需要加\(d_i\)次才能产生\(1\)的贡献 用线段树维护每个节点里\(d_i\)的最小值,每次当\(d_i - 1= 0\)的时候往下递归即可 时间复杂度:\(O(nlog^2 n)\) 多组数据记得清空lazy标记啊qwq.... #include<bits/stdc++.h> using namespace std; const…
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门  原题目描述在最下面. Solution:  每个节点用一个变量储存它所覆盖区间最少需要加多少次答案能加1.  如果这次更新不能使答案加1,则更新到lazy标记就可以了,如果能让答案加1,就更新到叶子节点,具体看代码. AC_Code: #include<cstdio> #include<iostream> #include…
构造一个序列B[i]=-b[i],建一颗线段树,维护区间max, 每次区间加后再询问该区间最大值,如果为0就在树状数组中对应的值+1(该操作可能进行多次) 答案在树状数组中找 其实只用一颗线段树也是可以的 Code #include <cstdio> #include <algorithm> #include <cstring> #define mst(a) memset(a,0,sizeof(a)) #define N 100010 using namespace s…
原题地址 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…
Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Others)Total Submission(s): 3636    Accepted Submission(s): 1612 Problem Description In a galaxy far, far away, there are two integer sequence a and b of l…
题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 axmorz 思路 因为是整除,所以一次加法可以对ans 没有影响 当ai是bi的倍数,对ans会有贡献 所以我们维护一个sum,初值为bi(只对于线段树的叶子节点有用) 当区间+1的时候 我们对sum-1 当sum=0的时候(倍数) ans++,sum=bi 然后再维护一个区间最小值 当区间内的mi>…
Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Others)Total Submission(s): 2114    Accepted Submission(s): 915 Problem Description In a galaxy far, far away, there are two integer sequence a and b of le…
http://acm.hdu.edu.cn/showproblem.php?pid=6315 题意 a数组初始全为0,b数组为1-n的一个排列.q次操作,一种操作add给a[l...r]加1,另一种操作query查询Σfloor(ai/bi)(i=l...r). 分析 真的是太naive啦,现场时没做出来. 看见区间自然想起线段树,那么这里的关键就是整除问题,只有达到一定数量才会对区间和产生影响. 反过来想,先把a[i]置为b[i],那么每次add时就是-1操作,当a[i]为0时区间和+1,再把…
Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b is a static permutation of 1 to n. Initially a is filled with zeroes.There are two kind of operations:1. add l r: add one for al,al+1...ar2. query l r:…
题意:数量为N的序列a和b,a初始全为0,b为给定的1-N的排列.有两种操作:1.将a序列区间[L,R]中的数全部+1:2.查询区间[L,R]中的 ∑⌊ai/bi⌋(向下取整) 分析:对于一个位置i,如果ai<bi,那么该位置不能对结果做出贡献:而当某一次操作后,ai>=bi了,就对结果的贡献值+1.那么可以用在线段树的结点中维护每个区间的最大a和最小b,和已经产生的贡献cnt.如果一个区间中最大的a超过了b,那么就说明此次更新操作使该区间的结果产生了变化,那么就要向下找到那个产生贡献的位置.…
发现每次区间加只能加1,最多全局加\(n\)次,这样的话,最后的答案是调和级数为\(nlogn\),我们每当答案加1的时候就单点加,最多加\(nlogn\)次,复杂度可以得当保证. 然后问题就是怎么判断答案是否该加1.我们可以用线段树设初值为给出的排列,把区间加改成区间减,维护最小值.当最小值为0是遍历左右子树,找到该加1的节点,一共会找\(nlongn\)次复杂度也可以得到保证. #include<iostream> #include<cstring> #include<c…
hdu 6315 题意:对于一个数列a,初始为0,每个a[ i ]对应一个b[i],只有在这个数字上加了b[i]次后,a[i]才会+1. 有q次操作,一种是个区间加1,一种是查询a的区间和. 思路:线段树,一开始没用lazy,TLE了,然后开始想lazy的标记,这棵线段树的特点是,每个节点维护 :一个区间某个a 要增加1所需个数的最小值,一个区间已加上的mx的最大值标记,还有就是区间和sum. (自己一开始没有想到mx标记,一度想把lazy传回去. (思路差一点就多开节点标记. #include…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6315 In a galaxy far, far away, there are two integer sequence a and b of length n. b is a static permutation of 1 to n. Initially a is filled with zeroes. There are two kind of operations: 1. add l r: a…
题意:给定一个初始数组b和一个初始值全部为0的数组a,每次操作可以在给定的区间(l,r)内让a[i](l=<i<=r)加一,或者查询区间区间(l,r)中a[i]/b[i](l=<i<=r)(取整)的和.可以知道,$\sum_{\frac{a_i}{b_i}}\le nlogn$,所以我们只要暴力找到需要修改的位置修改即可..代码: #include<iostream> #include<cstdio> #include<cstring> #def…
The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automated statistic collecting and press analysis. We know that any of the k citizens can become a member of the Embezzland governm…
题意: 两个序列a和b,初始a[i]=0,b[i]给定且为一个1到n的排列,要求维护以下两种操作:1.区间[L,R]内a[i]加1 2.询问[L,R]内a[i]/b[i](下取整)之和 n,q<=1e5 思路: 实际上a[i]/b[i]的线段树可以改为树状数组,因为只需要支持单点修改和前缀区间求和 #include<cstdio> #include<cstring> #include<string> #include<cmath> #include&l…
链接:HDU-6315:Naive Operations 题意: In a galaxy far, far away, there are two integer sequence a and b of length n.b is a static permutation of 1 to n. Initially a is filled with zeroes.There are two kind of operations:1. add l r: add one for al,al+1...a…
题目:http://poj.org/problem?id=3468   A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 85851   Accepted: 26685 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with…
Crayon Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description Background Mary love painting so much, but as we know she can't draw very well. There is no one appreciate her works, so she come…
题目: http://acm.hdu.edu.cn/showproblem.php?pid=6315 Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Others) Problem Description In a galaxy far, far away, there are two integer sequence a and b of length…
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In…
You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. Input The firs…
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In…
http://acm.hdu.edu.cn/showproblem.php? pid=5372 Segment Game Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1284    Accepted Submission(s): 375 Problem Description Lillian is a clever girl so…
I. Yukino With Subinterval 题目链接: Problem Descripe Yukino has an array \(a_1, a_2 \cdots a_n\). As a tsundere girl, Yukino is fond of studying subinterval. Today, she gives you four integers $l, r, x, y $, and she is looking for how many different sub…
Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with the query like to simply find the k-th smallest number of the given N numbers. They…
1.HDU 1556  Color the ball   区间更新,单点查询 2.题意:n个气球,每次给(a,b)区间的气球涂一次色,问最后每个气球各涂了几次. (1)树状数组 总结:树状数组是一个查询和修改复杂度都为log(n)的数据结构.主要用于查询任意两位之间的所有元素之和,但是每次只能修改一个元素的值. 这里改下思路可以用树状数组.在更新(a,b)时,向上更新,将a~n加1,b+1~n减1.查询点时,向下求和即可. #include<iostream> #include<cstr…
HDU 3966 Aragorn's Story 先把树剖成链,然后用树状数组维护: 讲真,研究了好久,还是没明白 树状数组这样实现"区间更新+单点查询"的原理... 神奇... #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #inc…
谁再管这玩意叫树状数组套主席树我跟谁急 明明就是树状数组的每个结点维护一棵动态开结点的权值线段树而已 好吧,其实只有一个指针,指向该结点的权值线段树的当前结点 每次查询之前,要让指针指向根结点 不同结点的权值线段树之间毫无关联 可以看这个:http://blog.csdn.net/popoqqq/article/details/40108669?utm_source=tuicool #include<cstdio> #include<algorithm> using namespa…
题目链接: 传送门 Minimum Inversion Number Time Limit: 1000MS     Memory Limit: 32768 K Description The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj. For a given sequence of numbe…