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的更多相关文章
随机推荐
- XCTF IgniteMe
一.查壳 结论: 1.用vc++编译的. 2.无壳,毕竟是一分的题 二.点击运行,发现不是爆破,而是找出注册机,汇编功力还在提升中,只能拖入ida来静态调试了 具体的见注释: 二.1点击进入关键函数 ...
- Ubuntu20.4 bs4安装的正确姿势
一.背景 公司一小伙子反馈在内网机器上通过代理,还是安装不了bs4:于是乎,作为菜鸡的我开始排查.一直认为是网络和代理问题,所以关注点一直放在网络和安装包上:在网上搜索到,主要是以下问题: 1)更新a ...
- 攻防世界-crypto-Decrypt-the-Message(Poem Codes-诗歌密码)
题目来源:su-ctf-quals-2014题目描述:解密这段信息! 下载附件,内容如下 The life that I have Is all that I have And the life th ...
- win10禁止粘滞键 禁止按5次shift开启粘滞键
如果你感觉粘滞键的快捷键影响了你的使用或想强行更改连续按5次上档键的指向的话,建议用你需要的程序替换%windir%\system32文件夹下面的sethc.exe @echo offclsdel / ...
- mysql 修改my.ini
1.C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqladmin shutdown可能提示:localhost不能启动mysql2.C:\Prog ...
- SQL USE语句(选择数据库)
对于大型的软件系统,会存在多个数据库,用来存储不同的数据,那么我们在开始操作之前,需要选择一个需要操作的数据库,进行后续数据的增.删.改.查工作. SQL USE语句用于选择SQL模式中的任何现有数据 ...
- python之数据驱动ddt操作(方法二)
import unittestfrom ddt import ddt,unpack,datafrom selenium import webdriverfrom selenium.webdriver. ...
- 深入学习Netty(5)——Netty是如何解决TCP粘包/拆包问题的?
前言 学习Netty避免不了要去了解TCP粘包/拆包问题,熟悉各个编解码器是如何解决TCP粘包/拆包问题的,同时需要知道TCP粘包/拆包问题是怎么产生的. 在此博文前,可以先学习了解前几篇博文: 深入 ...
- React refs 的理解
一.是什么 Refs 在计算机中称为弹性文件系统(英语:Resilient File System,简称ReFS) React 中的 Refs提供了一种方式,允许我们访问 DOM节点或在 render ...
- 解决 centerOS7部署ajango2.2.x版本 报SQLite 3.8.3 or later is required (found 3.7.17).错误
在CentOS7上部署Django的时候,遇到了一些问题,写篇笔记记录解决过程. 报错信息 当python3 manage.py runserver启动django项目的时候,就会出现报错信息如下: ...