要求一段最大的区间里每个能力的增长值是一样的。

我们首先求一遍前缀和,发现,如果区间内[l,r]每个能力的增长值是一样的话,那么前缀和[r]和[l-1]的差分也应该是一样的。

那么我们把前缀和的差分hash一下,排个序,求出hash值相同的且跨越最远的两个端点,就是答案了。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... int a[N], wei[N][];
struct Node{int hash, id;}node[N]; bool comp(Node a, Node b){
if (a.hash!=b.hash) return a.hash<b.hash;
return a.id<b.id;
}
int main ()
{
int n, m, x;
scanf("%d%d",&n,&m);
FOR(i,,n) {
scanf("%d",&x);
int num=;
while (x) wei[i][++num]=x%, x/=;
FOR(j,,m) wei[i][j]+=wei[i-][j];
}
FOR(i,,n) {
int val=;
FOR(j,,m) val=val*+wei[i][j]-wei[i][j-];
node[i].hash=val; node[i].id=i;
}
sort(node,node+n+,comp);
int ans=, l, r;
FOR(i,,n) {
if (i==||node[i].hash!=node[i-].hash) l=node[i].id;
if (i==n||node[i].hash!=node[i+].hash) r=node[i].id, ans=max(ans,r-l);
}
printf("%d\n",ans);
return ;
}

luogu 1360 阵容均衡(前缀和+差分+hash)的更多相关文章

  1. [LuoguP1360][USACP07MAR]黄金阵容均衡

    [LuoguP1360][USACP07MAR]黄金阵容均衡(Link) 每天会增加一个数\(A\),将\(A\)二进制分解为\(a[i]\),对于每一个\(i\)都增加\(a[i]\),如果一段时间 ...

  2. 洛谷 P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L…

    P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L… 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many simi ...

  3. Codeforces 479E Riding in a Lift:前缀和/差分优化dp

    题目链接:http://codeforces.com/problemset/problem/479/E 题意: 有一栋n层的房子. 还有一个无聊的人在玩电梯,每次玩电梯都会从某一层坐到另外一层. 他初 ...

  4. 洛谷P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L…

    P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L… 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many simi ...

  5. 北京区域赛I题,Uva7676,A Boring Problem,前缀和差分

    转载自https://blog.csdn.net/weixin_37517391/article/details/83821752 题解 其实这题不难,只要想到了前缀和差分就基本OK了. 我们要求的是 ...

  6. [CSP-S模拟测试]:stone(结论+桶+前缀和+差分)

    题目描述 $Cab$有两行石子,每个石子上有一个字母,为$'C''A''B'$中的一个.一开始,在每行第一个石子上站着一只$lucky$,$Cab$每次可以选择一个字母,使得所站石子上字母为该字母的$ ...

  7. HDU-6514 Monitor(二维前缀和+差分)

    http://acm.hdu.edu.cn/showproblem.php?pid=6514 Problem Description Xiaoteng has a large area of land ...

  8. [USACO07MAR]黄金阵容均衡Gold Balanced L…(洛谷 1360)

    题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to na ...

  9. [USACO07MAR]黄金阵容均衡Gold Balanced L…

    https://www.luogu.org/problem/show?pid=1360 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many s ...

随机推荐

  1. 20155331 《信息安全技术概论》实验二 Windows口令破解

    20155331 <信息安全技术概论>实验二 Windows口令破解 [实验目的] 了解Windows口令破解原理 对信息安全有直观感性认识 能够运用工具实现口令破解 [实验原理] 口令破 ...

  2. 微信小程序居中代码

    html页面: { text-align:center; } wxss页面: { width: 100%; height: 100%; display: flex; justify-content: ...

  3. angularJS ng-repeat中的directive 动态加载template

    有个需求,想实现一个html组件,传入不同的typeId,渲染出不同的表单元素. <div ng-repeat="field in vm.data"> <magi ...

  4. 一个奇怪的JS函数

    今天在分析一个jQuery插件源码的时候,发现了一个奇怪的函数. 这个函数的目的是为数字补零,如传入7,输出07,传入12输出12.由于是对时间补零,只截取后两位. // add leading ze ...

  5. Oracle用户和模式,表空间

    oracle 用户与表空间关系 oracle用户与表空间关系用户=商家表=商品表空间=仓库1. 1个商家能有很多商品,1个商品只能属于一个商家2. 1个商品可以放到仓库A,也可以放到仓库B,但不能同时 ...

  6. com.genuitec.runtime.generic.jee60 is not defined 导入项目的异常

    系统加载工程后,报错Target runtime com.genuitec.runtime.generic.jee60 is not defined,在发布工程的同事电脑上正常 新导入的工程,出问题很 ...

  7. PHP序列化serialize()和反序列化unserialize()

    所谓的序列化,就是把保存在内存中的各种对象状态或属性保存起来,在需要时可以还原出来. serialize() 可处理除了 resource 之外的任何类型返回字符串,此字符串包含了表示 value 的 ...

  8. python3 selenium实现自动登陆网页

    一.  安装python3与pycharm python安装参考链接:https://www.cnblogs.com/hepeilinnow/p/9727922.html pycharm最好安装专业版 ...

  9. 03-运行第一个docker容器

    环境选择 容器需要管理工具.runtime 和操作系统,我们的选择如下: 1.管理工具 - Docker Engine因为 Docker 最流行使用最广泛. 2.runtime - runc Dock ...

  10. EasyUI validatebox 自定义ajax验证用户名是否已存在

    <td><input type="text" id="userName" name="userName" class=&q ...