![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
前缀和
狠人王
怀着一颗热情的心,追随自己的梦想!
展开
-
2019icpc上海区域赛网络预赛B Light bulbs(离散化)
https://nanti.jisuanke.com/t/41399题意:给你一段区间,最初区间里的全部灯都是灭的,每次给你一段区间的两个端点,这个区间里的每一盏灯都变成相反的状态(灭变成亮,亮变成暗)#include<iostream>#include<cstdio>#include<cstring>#include<string>...原创 2019-10-11 21:28:34 · 179 阅读 · 0 评论 -
CodeForces 221D Little Elephant and Array(前缀和|莫队算法|树状数组)
这道题的题意是给你一串数字,再给你一对序号,满足1出现一次,2出现两次,3出现三次以此类推,找出某对序号中有多少数字满足以上规律。没做出来,题意看着简单,想着朴素解法就是可以的,但是网上大量的都是莫队算法,线段树,区间统计等等…不用也行,用了也不见得简单。D. Little Elephant and Arraytime limit per test4 secondsmemory limit ...原创 2019-07-24 10:11:09 · 220 阅读 · 0 评论 -
CodeForce 231C To Add or Not to Add(前缀和贪心)
A piece of paper contains an array of n integers a1, a2, …, an. Your task is to find a number that occurs the maximum number of times in this array.However, before looking for such number, you are al...原创 2019-07-30 15:53:32 · 148 阅读 · 0 评论 -
CodeForce 224B Array(优化前缀和|枚举)
You’ve got an array a, consisting of n integers: a1, a2, …, an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n) such, that among numbers al, al + 1, …, ar there are exact...原创 2019-07-25 17:16:02 · 186 阅读 · 0 评论 -
总结(前缀和与差分)
前缀和:一维前缀和: for(int i=1;i<=n;i++) { cin>>a[i]; sum[i]=sum[i-1]+a[i]; }初步:某个下标区间内的数组的和可用前缀和相减表示。扩展:统计某个下标区间内某个数字出现的个数(CF-221D)把一个数组从中间p位置分开,使得a[0]+…+a[p-1]与a[p]+a[p+...原创 2019-07-26 11:33:34 · 325 阅读 · 0 评论 -
C. Primes on Interval
time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output*You’ve decided to carry out a survey in the theory of prime numbers. Let us remind you tha...原创 2019-08-03 21:55:58 · 154 阅读 · 0 评论 -
【51nod】2494最长配对(前缀和)(思维)
小b有一个01序列,她想找到一个最长的区间使得这个区间的01能两两配对,即0的个数和1的个数相等。求最长区间的长度。输入第一行一个正整数n,表示数组长度,其中0<n≤50000;第二行n个0或1,以空格隔开。输出输出一个数,表示最长区间的长度输入样例30 1 0输出样例2分析:对0和1进行前缀和预处理,二重循环枚举即可。注意枚举时区间右端点可以从小端点+1取,即j=i+1,...原创 2019-08-07 17:15:11 · 136 阅读 · 0 评论