codeforces 1186E- Vus the Cossack and a Field
传送门:QAQQAQ
题意:给一个01矩阵A,他的相反矩阵为B,每一次变换都会将原矩阵面积乘4成为:
AB
BA
矩阵的左上角固定,变换无限次,现有q个询问,即求一个矩阵内的1的个数。
思路:因为反转,所以A,B矩阵拼起来刚好是一个全都为1的矩阵,所以答案就是匹配的A,B矩阵总点数/2和右下角1的个数之和
注意点:
1.因为数据较大,要用前缀和思想
2.要开longlong
3.注意询问时各个变量的重置
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int A[][],B[][],a[][],b[][];
int sa[][],sb[][];
ll n,m,q,t[];
void init()
{
t[]=;
for(int i=;i<=;i++) t[i]=t[i-]*;
memset(sa,,sizeof(sa));
memset(sb,,sizeof(sb));
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
sa[i][j]=sa[i-][j]+sa[i][j-]-sa[i-][j-]+A[i][j];
sb[i][j]=sb[i-][j]+sb[i][j-]-sb[i-][j-]+B[i][j];
}
}
}
int s=;
void judge(ll x)//even->A odd->B
{
for(int i=;i>=;i--)
{
if(t[i]<x) x-=t[i],s++;
}
}
ll solve(ll x,ll y)
{
s=;
ll ret=;
if(x==||y==) return ;
ret+=(x*y-(x%(*n))*(y%(*m)))/;//n,m写错
ll xx=x-x%(*n)+;
ll yy=y-y%(*m)+;
ll tx=(xx-)/n+;
ll ty=(yy-)/m+;
judge(tx); judge(ty);
ll dx=x-xx+,dy=y-yy+;
if(s%==)
{
if(dx<=n&&dy<=m) ret+=sb[dx][dy];
if(dx<=n&&dy>m) ret+=sa[dx][dy-m]+sb[dx][m];
if(dx>n&&dy<=m) ret+=sb[n][dy]+sa[dx-n][dy];
if(dx>n&&dy>m) ret+=sb[n][m]+sa[n][dy-m]+sa[dx-n][m]+sb[dx-n][dy-m];
}
else
{
if(dx<=n&&dy<=m) ret+=sa[dx][dy];
if(dx<=n&&dy>m) ret+=sb[dx][dy-m]+sa[dx][m];
if(dx>n&&dy<=m) ret+=sa[n][dy]+sb[dx-n][dy];
if(dx>n&&dy>m) ret+=sa[n][m]+sb[n][dy-m]+sb[dx-n][m]+sa[dx-n][dy-m];
}
return ret;
}
int main()
{
scanf("%lld%lld%lld",&n,&m,&q);
for(int i=;i<=n;i++)
{
char str[];
scanf("%s",str+);
for(int j=;j<=m;j++)
{
A[i][j]=str[j]-'';
B[i][j]=(str[j]-'')^;
}
}
init();
while(q--)
{
ll x1,y1,x2,y2;//开ll
scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);//s不在这里重置
ll ans=solve(x2,y2)-solve(x1-,y2)-solve(x2,y1-)+solve(x1-,y1-);
printf("%lld\n",ans);
}
}
codeforces 1186E- Vus the Cossack and a Field的更多相关文章
- E. Vus the Cossack and a Field (求一有规律矩形区域值) (有一结论待证)
E. Vus the Cossack and a Field (求一有规律矩形区域值) 题意:给出一个原01矩阵,它按照以下规则拓展:向右和下拓展一个相同大小的 0 1 分别和原矩阵对应位置相反的矩阵 ...
- Codeforces F. Vus the Cossack and Numbers(贪心)
题目描述: D. Vus the Cossack and Numbers Vus the Cossack has nn real numbers aiai. It is known that the ...
- 『Codeforces 1186E 』Vus the Cossack and a Field (性质+大力讨论)
Description 给出一个$n\times m$的$01$矩阵$A$. 记矩阵$X$每一个元素取反以后的矩阵为$X'$,(每一个cell 都01倒置) 定义对$n \times m$的矩阵$A$ ...
- codeforces 1186C Vus the Cossack and Strings
题目链接:https://codeforc.es/contest/1186/problem/C 题目大意:xxxxx(自认为讲不清.for instance) 例如:a="01100010& ...
- Codeforces 1186F - Vus the Cossack and a Graph 模拟乱搞/欧拉回路
题意:给你一张无向图,要求对这张图进行删边操作,要求删边之后的图的总边数 >= ceil((n + m) / 2), 每个点的度数 >= ceil(deg[i] / 2).(deg[i]是 ...
- @codeforces - 1186F@ Vus the Cossack and a Graph
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 点 m 边的图(n, m<=10^6),记第 ...
- CodeForces - 1186 C. Vus the Cossack and Strings (异或)
Vus the Cossack has two binary strings, that is, strings that consist only of "0" and &quo ...
- Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)
C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...
- Codeforces Round #571 (Div. 2)-D. Vus the Cossack and Numbers
Vus the Cossack has nn real numbers aiai. It is known that the sum of all numbers is equal to 00. He ...
随机推荐
- more指令和less指令使用的区别
more和less都是可以一页一页的翻动 more翻页的时候,显示有百分比在最下一行 less没有 more可以用来查询 空白键 (space):代表向下翻一页:Enter :代表向下翻『一行』:/字 ...
- 两个对象值相同 (x.equals(y) == true),但却可有不同的 hash code,这句话对不对?
不对,如果两个对象x和y满足x.equals(y) == true,它们的哈希码(hash code)应当相同.Java对于eqauls方法和hashCode方法是这样规定的: (1)如果两个对象相同 ...
- 异或前缀和——cf1186C
很思维的题,b的1个数和c的1个数相差为偶数时,必定有偶数个不同 反之必定有奇数个不同 #include <iostream> #include <cstdlib> #incl ...
- kubernetes istio之gateway
[root@master istio-]# kubectl apply -f samples/httpbin/httpbin.yaml service/httpbin created deployme ...
- C++——多态
1. 多态定义的构成条件 多态是在不同继承关系的类对象,去调同一函数,产生了不同的行为. 就是说,有一对继承关系的两个类,这两个类里面都有一个函数且名字.参数.返回值均相同,然后我们通过调用函数来实现 ...
- Linux课程---14、linux下lamp环境如何安装
Linux课程---14.linux下lamp环境如何安装 一.总结 一句话总结: 要按顺序安装,比如apache需要在php之前安装, 一.安装 gcc 编译器 二.卸载 rpm 安装的 http ...
- Linux课程---12、linux中内存指令(top命令的作用是什么)
Linux课程---12.linux中内存指令(top命令的作用是什么) 一.总结 一句话总结: top实时观察进程.内存和CPU情况 1.电脑出现反应慢情况,最先想到的是什么? 内存 2.linux ...
- Wed Nov 01 13:03:16 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended.
报错:Wed Nov 01 13:03:16 CST 2017 WARN: Establishing SSL connection without server's identity verifica ...
- day22_4-pickle模块
# 参考资料:# python模块(转自Yuan先生) - 狂奔__蜗牛 - 博客园# https://www.cnblogs.com/guojintao/articles/9070485.html ...
- ZOJ-1107-FatMouse and Cheese-dfs+记忆化搜索
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...