随笔分类 - RMQ---树状数组
摘要:题意:现在给定空空的三维平面,有加点操作和询问立方体点数。 思路:考虑CDQ套CDQ。复杂度是O(NlogN*logN*logN),可以过此题。 具体的,这是一个四维偏序问题,4维分别是(times,x,y,z);我们知道cdq可以求出t<=T,x=X,y<=Y,在套一层就可以z<=Z了。那么一个立
阅读全文
摘要:题意:询问区间有多少个连续的段,而且这段的颜色在[L,R]才算贡献,每段贡献是1。 有单点修改和区间查询。 思路:46min交了第一发树套树,T了。 稍加优化多交几次就过了。 不难想到,除了L这个点,其他的点都可以只统计这一段的段首。把位置看成x,颜色看成y,就成了二维平面就矩形内点的个数,这就是裸
阅读全文
摘要:链接:https://ac.nowcoder.com/acm/contest/926/D来源:牛客网 在一维坐标系中,给定 n条有颜色的线段,第 i条线段的左右端点分别为 li和 ri,此外它的颜色为 ci。 给定m个查询,每个查询给定一个区间 [a,b],需要求出这个区间完全包含的线段中有多
阅读全文
摘要:pro:给定N+1个点的树,有M对关键点,现在让你破坏最少的点,使得M对关键点不连通。 sol:贪心,我们把M对点按照LCA深度排序,每次破坏LCA。 如果一对点(u,v,lca),u-lca-v有点被破坏,则可以不用破坏新的点。 我们可以用dfs序+树状数组来处理。 如果破坏了一个点,则给它的子树
阅读全文
摘要:Sample Input Sample Output Prof.Q is a sophisticated professor who has insights into quadrillions of sorting algorithms, especially into bubble sort.
阅读全文
摘要:A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is
阅读全文
摘要:n players are going to play a rock-paper-scissors tournament. As you probably know, in a one-on-one match of rock-paper-scissors, two players choose t
阅读全文
摘要:Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long as possible but he doesn't remember exactly the hei
阅读全文
摘要:题意:给定字符串char[],以及Q个操作,操作有三种: 1:pos,chr:把pos位置的字符改为chr 2:pos:问以pos为中心的回文串长度为多长。 3:pos:问以pos,pos+1为中心的回文串长度为多长。 思路:用hash表示一段字符串或者连续子串。我们用BIT记录hash前缀和,那么
阅读全文
摘要:The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automated statistic collecting and p
阅读全文
摘要:墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问。墨墨会像你发布如下指令: 1、 Q L R代表询问你从第L支画笔到第R支画笔中共有几种不同颜色的画笔。 2、 R P Col 把第P支画笔替换为颜色Col。为了满足墨墨的要求,你知道你需要干什么了吗? Input 第
阅读全文
摘要:DCE Coders admins are way much geekier than they actually seem! Kartik has been following that tradition lately. How? Well, he took the inversion coun
阅读全文
摘要: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
阅读全文
摘要:You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input
阅读全文
摘要:Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1 <=
阅读全文
摘要: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
阅读全文
摘要:Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares fo
阅读全文
摘要:You may have wondered why most extraterrestrial life forms resemble humans, differing by superficial traits such as height, colour, wrinkles, ears, ey
阅读全文
摘要:Time limit per test: 1.0 seconds Memory limit: 256 megabytes Time limit per test: 1.0 seconds Memory limit: 256 megabytes Time limit per test: 1.0 sec
阅读全文
摘要:题意: 给出一个矩阵,初始每个位置上的值都为0,然后有两种操作 一种是更改某个位置上的值 另一种是求某个位置附近曼哈顿距离不大于K的所有位置的值的总和 技巧: 坐标旋转,使得操作之后菱形变成方方正正的矩形,(即“曼哈顿距离”转化为“切比雪夫距离”)方便使用树状数组进行计算。 利用哈希进行离散,节约空
阅读全文