noip38
T1
有个朴素的暴力,枚举每一个子矩形,复杂度 \(O(n^{2}m^{2})\),观察数据范围,n很小,考虑枚举行,对于 \(m\) 用 \(two\;pointers\) 来维护。
先预处理出每一列的前缀和,然后枚举行,对于列,用个双指针,把 \([l,r]\) 这一段区间卡出来,答案每回累加合法的区间长度即可。
复杂度 \(O(n^{2}m)\)
Code
#include<cmath>
#include<cstdio>
#define MAX 50100
#define re register
#define int long long
namespace OMA
{
char ch[MAX];
int n,m,l,r,tot[MAX];
int ans,sum[33][MAX];
struct stream
{
template<typename type>inline stream &operator >>(type &s)
{
int w=1; s=0; char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-')w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ s=s*10+ch-'0'; ch=getchar(); }
return s*=w,*this;
}
}cin;
signed main()
{
//freopen("node.in","r",stdin);
cin >> n >> m;
for(re int i=1; i<=n; i++)
{
scanf("%s",ch+1);
for(re int j=1; j<=m; j++)
{ sum[i][j] = sum[i-1][j]+(ch[j]=='1'); }
}
cin >> l >> r;
for(re int i=1; i<=n; i++)
{
for(re int j=i; j<=n; j++)
{
int lp = 0,rp = 0;
for(re int k=1; k<=m; k++)
{
//printf("i=%lld j=%lld k=%lld ",i,j,k);
tot[k] = tot[k-1]+sum[j][k]-sum[i-1][k];
//printf("tot[%lld]=%lld\n",k,tot[k]);
while(tot[k]-tot[lp]>r&&lp+1<k)
{ lp++; }
while(tot[k]-tot[rp+1]>=l&&rp+1<k)
{ rp++; }
if(tot[k]-tot[rp]>=l)
{ ans += rp-lp+1; }
}
}
}
printf("%lld\n",ans);
return 0;
}
}
signed main()
{ return (OMA::main(),0); }
T2
题意转换

好了,现在你已经知道转换后的题意,问题在于如何求解 \(cnt\) 数组和答案。
对于每一行,我们都开一个桶记录 \(a\) 出现的次数。
然后枚举每一行,再从1枚举到最大值,再枚举当前枚举的数的倍数,加上上边说的桶即可 建议看code
这样得到的 \(cnt_{i,j}\) 表示第i行有多少个数为j的倍数,每一行求和就是总的,而我们要的是j,所以考虑一波容斥,即减去j的其他倍数即可,这样的话就要倒序枚举最大值。
复杂度 \(O(n(m+\max\{a\}\ln\max\{a\}))\) 。
Code
#include<cstdio>
#define MAX 100010
#define re register
#define int long long
const int N = 22;
namespace OMA
{
int n,m,xam,ans;
int a[N][MAX];
int buc[N][MAX];
int cnt[N][MAX],sum[MAX];
const int p = 1e9+7;
struct stream
{
template<typename type>inline stream &operator >> (type &s)
{
int w=1; s=0; char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-')w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9'){ s=s*10+ch-'0'; ch=getchar(); }
return s*=w,*this;
}
}cin;
inline int max(int a,int b)
{ return a>b?a:b; }
signed main()
{
cin >> n >> m;
for(re int i=1; i<=n; i++)
{
for(re int j=1; j<=m; j++)
{ cin >> a[i][j]; xam = max(xam,a[i][j]); buc[i][a[i][j]]++; }
}
for(re int i=1; i<=n; i++)
{
for(re int j=1; j<=xam; j++)
{
for(re int k=1; j*k<=xam; k++)
{ cnt[i][j] += buc[i][j*k]; }
}
}
/*for(re int i=1; i<=n; i++)
{
for(re int j=1; j<=xam; j++)
{ printf("%lld ",cnt[i][j]); }
printf("\n");
}*/
for(re int j=xam; j; j--)
{
sum[j] = 1;
for(re int i=1; i<=n; i++)
{ (sum[j] *= cnt[i][j]+1) %= p; }
sum[j] -= 1;
if(!sum[j])
{ continue ; }
for(re int k=2; k*j<=xam; k++)
{ sum[j] -= sum[k*j]; }
(ans += j*sum[j]) %= p;
}
printf("%lld\n",(ans+p)%p);
return 0;
}
}
signed main()
{ return OMA::main(); }
T3
点分治,不会,爬了
noip38的更多相关文章
随机推荐
- linux学习之路第八天(组管理和权限管理)
组管理和权限管理 1.Linux 组基本介绍 在linux中的每个用户必须属于一个组,不能独立于组外.在linux中每个文件有所有者,所在组,其他组的概念 1)所有者 2)所在组 3)其它组 4)改变 ...
- Vue | 路由守卫面试常考
前言 最近在整理基础,欢迎掘友们一起交流学习 结尾有彩蛋哦! Vue Router 路由守卫 导图目录 路由守卫分类 全局路由守卫 单个路由守卫 组件路由守卫 路由守卫执行的完整过程 路由守卫分类 全 ...
- PyVista:一款Python的三维可视化软件
技术背景 三维可视化是一项在工业领域中非常重要的技术,而Python中最热门的可视化工具matplotlib和plotly,更加倾向于在数据领域的可视化,用于展现数据的结果.类似的还有百度的pyech ...
- 【学习笔记】Tensor多维数组和axis的理解
Tensor多维数组和axis的理解 今天在编写程序的时候一直对于axis=0或等于1搞不明白,这样对于整个numpy或者是tensorflow的基本运算和数据处理都会很模糊,所以花了一些时间来搞清楚 ...
- Maven BOM!拿来吧你
what BOM? BOM(Bill of Materials)是由Maven提供的功能,它通过定义一整套相互兼容的jar包版本集合, 使用时只需要依赖该BOM文件,即可放心的使用需要的依赖jar包, ...
- 让Angular自定义组件支持form表单验证
Angular提供了一套非常强大的表单验证库(vue和react都需要第三方库的支持),可以非常方便简单实现web应用程序中的表单验证功能.但是如何让我们自定义的组件也支持验证呢? 我遇到一个需求是封 ...
- Hive开发要知道数据仓库的四个层次设计
数据仓库:数据仓库全面接收源系统数据,ETL进程对数据进行规范化.验证.清洗,并最终装载进入数据集市,通过数据集市支持系统进行数据查询.分析,整个数据仓库包含四大层次. 1.数据仓库的四个操作 ...
- odoo14在列表视图里添加自定义按钮
static/js/xxxx.js 这里定义按钮odoo.define('add.tree.view.buttons', function (require) { "use strict&q ...
- Scrapy+splash报错 Connection was refused by other side
报错信息如下: Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/scrap ...
- vue知识点----element UI+vue关于日期范围选择的操作,picker-options属性的使用
需求场景如下: 指定起止日期,后选的将会受到先选的限制 不同的日期选择器,不过也存在关联关系 实现方法不难,利用了 change 事件,动态改变 picker-options 中的 disableDa ...