线性结构——前缀和
Alex_McAvoy
想要成为渔夫的猎手
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
线性结构 —— 前缀和
【概述】 前缀和是一种及其优秀的线性结构,也是一种重要的思想,能极大的降低区间查询的时间复杂度。 前缀和又分为一维前缀和、二维前缀和,其与差分数组密切相关,关于差分数组:点击这里 【一维前缀和】 假设有一串长度为 n 的序列,再给出 m 次询问,每次询问给出 L、R 两个数,要求求出区间[L,R] 的和,如果不使用前缀和的话,每次都遍历一遍给出的区间,计算出答案,这样时间复杂度会达到 O...原创 2019-03-24 22:21:59 · 987 阅读 · 1 评论 -
循环数组最大字段和(51Nod-1050)
题目 N个整数组成的循环序列a[1],a[2],a[3],…,a[n],求该序列如a[i]+a[i+1]+…+a[j]的连续的子段和的最大值(循环序列是指n个数围成一个圈,因此需要考虑a[n-1],a[n],a[1],a[2]这样的序列)。当所给的整数均为负数时和为0。 例如:-2,11,-4,13,-5,-2,和最大的子段为:11,-4,13。和为20。 输入 第1行:整数序列的长度N(...原创 2019-04-15 21:48:14 · 383 阅读 · 0 评论 -
Little Xor(CF-252A)
Problem Description Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to fi...原创 2019-08-12 15:49:39 · 610 阅读 · 0 评论 -
Table with Letters-2(CF-253D)
Problem Description Vasya has recently started to learn English. Now he needs to remember how to write English letters. He isn't sure about some of them, so he decided to train a little. He found a...原创 2019-08-14 15:25:50 · 251 阅读 · 0 评论 -
Weather(CF-234C)
Problem Description Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet. Our hero Vasya is q...原创 2019-07-31 09:32:47 · 315 阅读 · 0 评论 -
RGB Substring (hard version) (CF-1196D2)
Problem Description The only difference between easy and hard versions is the size of the input. You are given a string ss consisting of nn characters, each character is 'R', 'G' or 'B'. You are a...原创 2019-07-25 17:21:24 · 359 阅读 · 0 评论 -
小a的轰炸游戏
【题目描述】 小a正在玩一款即时战略游戏,现在他要用航空母舰对敌方阵地进行轰炸 地方阵地可以看做是n×m的矩形 航空母舰总共会派出q架飞机。 飞机有两种,第一种飞机会轰炸以(xi,yi)为中心,对角线长为li的正菱形(也就是两条对角线分别于x轴y轴平行的正方形),而第二种飞机只会轰炸正菱形的上半部分(包括第xi行) (具体看样例解释) 现在小a想知道所有格子被轰炸次数的异或和 注意:不保证被轰...原创 2019-02-11 21:48:57 · 503 阅读 · 0 评论 -
和为S(51Nod-2518)
题目 小b有一个01序列A,她想知道A有多少个非空连续子序列和为S。 你能帮帮她吗? 输入 第一行输入一个数n,表示A的长度; 第二行输入n个数‘0’或‘1’,表示A中的元素,以空格隔开; 第三行输入一个非负整数S; 其中0≤S≤n≤30000。 输出 输出一个数,表示子数组的个数 输入样例 5 1 0 1 0 1 2 输出样例 4 思路:维护一个前缀和即可 源程序 ...原创 2019-07-30 10:13:45 · 390 阅读 · 0 评论 -
最长配对(51Nod-2494)
题目 小b有一个01序列,她想找到一个最长的区间使得这个区间的01能两两配对,即0的个数和1的个数相等。求最长区间的长度。 输入 第一行一个正整数n,表示数组长度,其中0<n≤50000; 第二行n个0或1,以空格隔开。 输出 输出一个数,表示最长区间的长度 输入样例 3 0 1 0 输出样例 2 思路: 由于要求最长区间使得 0、1 能够两两配对,那么可以将 0 转成 ...原创 2019-07-30 11:24:33 · 384 阅读 · 4 评论 -
Checker(AtCoder-3876)
Problem Description AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K. Here, a checked pattern of side K is a pattern where each square is painted blac...原创 2019-07-18 21:31:23 · 378 阅读 · 0 评论 -
Splitting Pile(AtCoder-2654)
Problem Description Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer ai written on it. They will share these cards. First, Snuke will take some number of cards f...原创 2019-06-15 13:44:08 · 517 阅读 · 0 评论 -
海啸
【题目描述】 有一个沿海地区,可以看作有n行m列的城市,第i行第j列的城市海拔为h[j]。 由于沿海,所以这个地区经常会发生海啸。 海啸发生时,部分城市会被淹没,具体来说,海水高度会达到d,因此海拔低于d的城市都会被淹没。 现在有q次询问,每次问你一个矩形区域中,有多少城市不会被淹没。 【输入描述】 第一行三个整数n,m,d,具体含义见题目描述。 接下来n行,每行m个整数,其中第i行第j列...原创 2019-05-27 16:09:31 · 399 阅读 · 0 评论 -
和为k的倍数(51Nod-2522)
题目 小b喜欢和为K的倍数的序列。 现在有一个长度为n的序列A,请问A有多少个非空连续子序列是小b喜欢的。 输入 第一行输入一个正整数n; 第二行输入n个整数,表示A[i],以空格隔开; 第三行输入一个正整数K; 其中1≤n≤30000,对于任意A[i]有-10000≤A[i]≤10000,2≤K≤10000 输出 输出一个数,表示子序列的数目 输入样例 6 4 5 0 -2 -...原创 2019-05-13 15:52:41 · 1953 阅读 · 1 评论 -
キャンディーとN人の子供 / Children and Candies(AtCoder-2021)
Problem Description 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently ...原创 2019-05-19 16:47:17 · 563 阅读 · 0 评论 -
01串(51Nod-1391)
题目 给定一个01串S,求出它的一个尽可能长的子串S[i..j],满足存在一个位置i<=x <j, S[i..x]中0比1多,而S[x + 1..j]中1比0多。求满足条件的最长子串长度。 输入 一行包含一个只由0和1构成的字符串S。 S的长度不超过1000000。 输出 一行包含一个整数,表示满足要求的最长子串的长度。 输入样例 10 输出样例 0 思路: ...原创 2019-05-02 21:32:12 · 947 阅读 · 0 评论 -
和为k的连续区间(51Nod-1094)
题目 一整数数列a1, a2, ... , an(有正有负),以及另一个整数k,求一个区间[i, j],(1 <= i <= j <= n),使得a[i] + ... + a[j] = k。 输入 第1行:2个数N,K。N为数列的长度。K为需要求的和。(2 <= N <= 10000,-10^9 <= K <= 10^9) 第2 - N + 1行:...原创 2019-04-17 18:25:54 · 1085 阅读 · 0 评论 -
Lines(HDU-5124)
Problem Description John has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to know how many lines cover A. Input The first lin...原创 2019-01-18 20:26:36 · 458 阅读 · 0 评论
分享